crypto

package
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

----------------------------------------------------------------- * L o r d O f S c r i p t s (tm) * Copyright (C)2025 Dídimo Grimaldo T. * APP_NAME * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * *-----------------------------------------------------------------

----------------------------------------------------------------- * L o r d O f S c r i p t s (tm) * Copyright (C)2025 Dídimo Grimaldo T. * APP_NAME * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * *-----------------------------------------------------------------

----------------------------------------------------------------- * L o r d O f S c r i p t s (tm) * Copyright (C)2025 Dídimo Grimaldo T. * APP_NAME * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * A public controller for Caesar-class substitution cipher encryption * and decryption. It supports plain Caesar, Didimus, Fibonacci & Primus. *-----------------------------------------------------------------

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CaesarCipherMode

type CaesarCipherMode uint8
const (
	CaesarMode CaesarCipherMode = iota
	DidimusMode
	FibonacciMode
	PrimusMode
)

func ParseCipherMode

func ParseCipherMode(s string) (CaesarCipherMode, error)

func (CaesarCipherMode) String

func (cm CaesarCipherMode) String() string

type CaesarKey

type CaesarKey struct {
	Letter rune
	Shift  int
}

func (CaesarKey) String

func (ck CaesarKey) String() string

implement fmt.Stringer. Returns key letter and shift

type CipherController

type CipherController struct {
	ControllerBase
	// contains filtered or unexported fields
}

The CipherController object holds a reference alphabet and can perform repeated, independent Encryption/Decryption operations on that alphabet with different parameter values.

func NewCipherController

func NewCipherController(alpha *caesardisk.AlphabetModel, vwn IViewNotifier) *CipherController

func (*CipherController) CloneWith

func (cc *CipherController) CloneWith(newAlpha *caesardisk.AlphabetModel) *CipherController

func (*CipherController) Decrypt

func (cc *CipherController) Decrypt(mode CaesarCipherMode, ciphered string, keyShift int, args ...any) (string, error)

Decrypts a Caesar-class string using the selected cipher mode and decryption parameters.

func (*CipherController) Encrypt

func (cc *CipherController) Encrypt(mode CaesarCipherMode, plain string, keyShift int, args ...any) (string, error)

Encrypt a plain string using the selected Caesar-class cipher mode with the selected encryption parameters.

func (*CipherController) PackMessage

func (cc *CipherController) PackMessage(cipherPayload string) string

takes an already encrypted string and packages it in a PDU that can be sent over the communications channel.

func (*CipherController) UnpackMessage

func (cc *CipherController) UnpackMessage(pdu string, mode CaesarCipherMode, keyShift int, keyOffset int) (string, error)

takes a PDU that contains an encrypted message from a communications channel and unpacks it to verify the metadata and if successful, return the decrypted payload.

type ControllerBase

type ControllerBase struct {
	// contains filtered or unexported fields
}

All controllers should implement this base object and extend it

type ICaesarKeyService

type ICaesarKeyService interface {
	// get the current Caesar key as letter (alphabet-dependent) and shift
	GetKey() (rune, int)
	SetKey(rune, int)

	Update()
}

The View that presents the main key must implement this interface. The SessionController consumes this service to notify changes to the GUI that are cascaded as a response to another change.

type IKeyOffsetService

type IKeyOffsetService interface {
	// get the current RAW/uncorrected Caesar key offset
	GetOffset() int
	// get the alternate key (letter & shift) derived from the corrected offset
	GetAltKey() (rune, int)
	SetOffsetRune(rune)
	SetOffset(rune, int)

	Hide()
	Show()
	Reset()
	Update()
}

The View that presents the offset & alternate key must implement this interface. SessionController consumes this service to notify of cascaded changes in response to a request.

type IViewNotifier

type IViewNotifier interface {
	// the 1st parameter is true for an error, false for informational.
	// the 2nd parameter is the message to be displayed
	Notify(bool, string)
}

The view should implement this interface to pop up a dialog when the controller needs to notify of changes that were made that require the attention of the user.

type IWheelUpdateService

type IWheelUpdateService interface {
	Update()
	CanShowOffset(bool)
	IsShowingMain() bool
}

When the SessionController responds to changes in the crypto parameters that affect the visual wheel, we must request a wheel update.

type SessionModel

type SessionModel struct {
	Mode    CaesarCipherMode // Caesar cipher mode (Caesar|Didimus|Fibonacci|Primus)
	Alpha   caesardisk.AlphabetModel
	MainKey CaesarKey // Main Caesar key (required)
	AltKey  CaesarKey // Alternate Caesar key (for Didimus only)
	Offset  int       // Offset (for Didimus) from which alternate key is derived
}

SessionModel contains all the data needed to perform encryption/decryption with any of the supported Caesar modes.

func (SessionModel) String

func (sm SessionModel) String() string

implement fmt.Stringer. Returns mode, main key, offset, alternate key

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL