Documentation
¶
Overview ¶
Package ikmachine implements an encryption system based using rotors and transposition to emulate infinite key (one-time pad) encryption.
This is an encryption system based on the article in Dr. Dobbs Journal Volume 9, Number 94, 1984 titled An Infinite Key Encryption System by John A. Thomas and Joan Thersites.
Index ¶
- Constants
- Variables
- func N[Int intType](n Int, rnd *Rand) Int
- func Shuffle[S ~[]E, E any](s S, rnd *Rand) S
- type CipherBlock
- type IkMachine
- func (ikm *IkMachine) ApplyKey(machineType rune, key []byte) *IkMachine
- func (ikm *IkMachine) Index(idx ...*big.Int) (newIdx *big.Int)
- func (ikm *IkMachine) InitializeProformaEngine() *IkMachine
- func (ikm *IkMachine) MaximalStates() *big.Int
- func (ikm *IkMachine) StopIkMachine()
- func (ikm *IkMachine) String() string
- type Rand
- func (rnd *Rand) Int15n(max int16) int16
- func (rnd *Rand) Int31n(max int32) int32
- func (rnd *Rand) Int63n(max int64) int64
- func (rnd *Rand) Intn(max int) int
- func (rnd *Rand) New(src *IkMachine) *Rand
- func (rnd *Rand) Perm(n int) []int
- func (rnd *Rand) Read(p []byte) (n int, err error)
- func (rnd *Rand) StopRand()
- func (rnd *Rand) Uint64() uint64
- func (rnd *Rand) Uint64n(max uint64) uint64
Constants ¶
const ( BitsPerByte int = 8 CipherBlockSize int = 256 CipherBlockBytes int = CipherBlockSize / BitsPerByte Encryption rune = 'E' Decryption rune = 'D' )
Define constants needed for ikmachine
Variables ¶
var ( BigZero = big.NewInt(0) BigOne = big.NewInt(1) )
Functions ¶
Types ¶
type CipherBlock ¶
type CipherBlock []byte
CipherBlock is the data processed by the rotors and permutators. It consists of the length in bytes to process and the (32 bytes of) data to process.
func (CipherBlock) String ¶
func (cblk CipherBlock) String() string
String formats a string representing the CipherBlock.
type IkMachine ¶
type IkMachine struct {
Input chan CipherBlock
Output chan CipherBlock
// contains filtered or unexported fields
}
IkMachine defines the machine used to encrypt or decrypt the plaintext. It consists of rotors and permutators that are connected using channels to pass the data (32 bytes at a time) being encrypted/decrypted between the rotors and permutators.
func (*IkMachine) ApplyKey ¶
ApplyKey will update the IkMachine's rotors, permutators, and counter file key based on the given secret key. The rotors and permutators are updated in place 32 bytes at a time causing the partially update rotor and permutators to be used during the update process. This should increase the difficulty to discover the working rotors and permutators of the encryption machine.
func (*IkMachine) Index ¶
setIndex will set the index of the encryption/decryption machine (the point where the keystream will begin) by setting the index of the rotors, permutators, and counter of the ikmachine.
func (*IkMachine) InitializeProformaEngine ¶
Initialize the proforma encryption engine. Note that the rotors and permutators of the ikmachine are copies of the proforma rotors and permutators so that they are not changed during the process of initialization and encryption/decryption. This is to allow the test to work when running the package or file tests.
func (*IkMachine) MaximalStates ¶
MaximalStates returns the maximum number of states that the encryption/ decription machine can be in before repeating the same random sequence.
func (*IkMachine) StopIkMachine ¶
func (ikm *IkMachine) StopIkMachine()
StopIkMachine shuts down the IkMachine freeing up the resouces used.
type Rand ¶
type Rand struct {
// contains filtered or unexported fields
}
func (*Rand) Int15n ¶
Int15n returns, as an int16, a non-negative pseudo-random number in the half-open interval [0,n). It panics if n <= 0.
func (*Rand) Int31n ¶
Int31n returns, as an int32, a non-negative pseudo-random number in the half-open interval [0,n). It panics if n <= 0.
func (*Rand) Int63n ¶
Int63n returns, as an int64, a non-negative pseudo-random number in the half-open interval [0,n). It panics if n <= 0.
func (*Rand) Intn ¶
Intn returns, as an int, a non-negative pseudo-random number in the half-open interval [0,n)]. It panics if n <= 0.
func (*Rand) Perm ¶
Perm returns, as a slice of n ints, a pseudo-random permutation of the integers in the half-open interval [0,n).
func (*Rand) Read ¶
Read generates len(p) random bytes and writes them into p. It returns number of bytes readd and a possible error.
func (*Rand) StopRand ¶
func (rnd *Rand) StopRand()
StopRand will stop the random number generator. It is and error to call any function of the Rand object after calling StopRand.