gocipher

package
v0.0.0-...-d399f25 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Atbash = Affine{25, -1, 25}

Atbash is the Atbash symmetric cipher.

View Source
var ROT13 = Affine{1, 13, 1}

ROT13 is the ROT-13 symmetric cipher. For example, "ABCDEFGHIJKLM" becomes "NOPQRSTUVWXYZ".

View Source
var ROT18 = rot18{}

ROT18 is the ROT-18 symmetric cipher. For example, "ABCXYZ012" becomes "STUFGHijk"

View Source
var ROT47 = &ROTRange{47, '!', '~'}

ROT47 is the ROT-47 symmetric cipher. For example, "ABCabc" becomes "pqr234".

View Source
var ROT5 = &ROTRange{5, '0', '9'}

ROT5 is the ROT-5 symmetric cipher. For example, "1234567890" becomes "5678901234".

Functions

func KeyedAlphabet

func KeyedAlphabet(key, alphabet string) string

KeyedAlphabet creates an alphabet starting with a keyword. e.g. "Hello, World!", "ABCDEFGHIJKLMNOPQRSTUVWXYZ" becomes "HELOWRDABCFGIJKMNPQSTUVXYZ"

func KeyedAlphabetRange

func KeyedAlphabetRange(key string, min, max rune) string

KeyedAlphabetRange creates an alphabet in a range of chars starting with a keyword. Uppercase and lowercase are considered different characters. e.g. "HELLO, WORLD!", 'A', 'Z' becomes "HELOWRDABCFGIJKMNPQSTUVXYZ"

func MorseFormatBullets

func MorseFormatBullets(morse string) string

MorseFormatBullets replaces the .- characters in Morse text with •– so the characters are vertially centered.

func MorseFormatSpoken

func MorseFormatSpoken(morse string) string

MorseFormatSpoken replaces dots and dashes with dits and dahs in Morse text. https://en.wikipedia.org/wiki/Morse_code#Spoken_representation

func RandomKey

func RandomKey(length int) (string, error)

RandomKey creates a cryptographically secure pseudorandom key

func RemoveDuplicates

func RemoveDuplicates(text string) string

func RemovePunctuation

func RemovePunctuation(text string) string

RemovePunctuation removes any non alphabetic chars from a string.

func RestorePunctuation

func RestorePunctuation(original, modified string) (string, error)

RestorePunctuation - If punctuation was accidently removed, use this function to restore it. Requires the original string with punctuation.

func VigenereCrack

func VigenereCrack(cipher string, keyLen int) []int8

VigenereCrack finds the key with the letter frequencies closest to English.

Types

type Affine

type Affine struct {
	A, B, AInv int
}

Affine is a key for an Affine cipher

func NewAffine

func NewAffine(a, b int) (*Affine, error)

NewAffine creates an Affine. For a one-to-one mapping, a must be invertable, as in gcd(a, 26) == 1.

func NewCaesar

func NewCaesar(shift int) *Affine

NewCaesar constructs a Caesar cipher.

func (*Affine) Decipher

func (key *Affine) Decipher(text string) string

Decipher deciphers string using Affine cipher according to key.

func (*Affine) Encipher

func (key *Affine) Encipher(text string) string

Encipher enciphers string using Affine cipher according to key.

type CaesarKeyed

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

func NewCaesarKeyed

func NewCaesarKeyed(key string, shift int) *CaesarKeyed

func (*CaesarKeyed) Decipher

func (c *CaesarKeyed) Decipher(text string) string

Decipher deciphers string using keyed Caesar cipher according to key.

func (*CaesarKeyed) Encipher

func (c *CaesarKeyed) Encipher(text string) string

Encipher enciphers string using keyed Caesar cipher according to key.

type FracMorse

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

func NewFracMorse

func NewFracMorse(key string) (*FracMorse, error)

func (*FracMorse) Decipher

func (f *FracMorse) Decipher(text string) (string, error)

Decipher deciphers text using the fractionated Morse cipher acccording to the initialized key.

func (*FracMorse) Encipher

func (f *FracMorse) Encipher(text string) (string, error)

Encipher enciphers text using the fractionated Morse cipher acccording to the initialized key.

type Morse

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

func NewMorse

func NewMorse(alphabets ...MorseAlphabet) *Morse

func (*Morse) Decode

func (m *Morse) Decode(morse string) (string, error)

Decode converts Morse code into text

func (*Morse) Encode

func (m *Morse) Encode(text string) (string, error)

Encode converts text into Morse code

type MorseAlphabet

type MorseAlphabet uint
const (
	MorseInternational MorseAlphabet = iota
	MorseSymbols
	MorseProsigns
	MorseProsignsMultiLine
	MorseAbbrNumbers
	MorseAbbrNumbers2
	MorseNonEnglish
	MorseGreek
	MorseRussian
	MorseBulgarian
	MorseHebrew
	MorseArabic
	MorsePersian
	Wabun
	//SKATS
	MorseThai
)

type OTP

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

func NewOTP

func NewOTP(key string) *OTP

func (*OTP) Decrypt

func (otp *OTP) Decrypt(text string) (string, error)

Decrypt decrypts text using a one-time pad

func (*OTP) Encrypt

func (otp *OTP) Encrypt(text string) (string, error)

Encrypt encrypts text using a one-time pad

type Polybius

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

func NewPolybius

func NewPolybius(key string, size int, chars string) (*Polybius, error)

func (*Polybius) Decipher

func (p *Polybius) Decipher(text string) string

Decipher deciphers string using Polybius square cipher according to initialised key.

func (*Polybius) Encipher

func (p *Polybius) Encipher(text string) string

Encipher enciphers string using Polybius square cipher according to initialised key.

type RC4

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

RC4 is an instance of the RC4 cipher.

func NewRC4

func NewRC4(key string) *RC4

func (*RC4) Decipher

func (r *RC4) Decipher(text string) string

func (*RC4) Encipher

func (r *RC4) Encipher(text string) string

type RC4A

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

RC4A is an instance of the RC4A cipher, a variant of RC4 proposed by Souradyuti Paul and Bart Preneel.

func NewRC4A

func NewRC4A(key string) *RC4A

func (*RC4A) Decipher

func (r *RC4A) Decipher(text string) string

func (*RC4A) Encipher

func (r *RC4A) Encipher(text string) string

type ROT

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

func NewROT

func NewROT(key int, alphabet string) *ROT

func (*ROT) Decipher

func (r *ROT) Decipher(text string) string

Decipher deciphers string using ROT cipher with alphabet according to key.

func (*ROT) Encipher

func (r *ROT) Encipher(text string) string

Encipher enciphers string using ROT cipher with alphabet according to key.

type ROTRange

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

func NewROTRange

func NewROTRange(key int, min, max rune) *ROTRange

func (*ROTRange) Decipher

func (r *ROTRange) Decipher(text string) string

Decipher deciphers string using ROT cipher with ranged alphabet according to key. Uppercase and lowercase are considered different characters.

func (*ROTRange) Encipher

func (r *ROTRange) Encipher(text string) string

Encipher enciphers string using ROT cipher with ranged alphabet according to key. Uppercase and lowercase are considered different characters.

type Railfence

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

RailfenceKey is a key for a Rail-fence cipher

func NewRailfence

func NewRailfence(rails int) (*Railfence, error)

NewRailfence creates a Railfence.

func (*Railfence) Decipher

func (r *Railfence) Decipher(text string) (string, error)

Decipher deciphers string using Rail-fence cipher according to key

func (*Railfence) Encipher

func (r *Railfence) Encipher(text string) (string, error)

Encipher enciphers string using Rail-fence cipher according to key

type Trithemius

type Trithemius struct{}

func NewTrithemius

func NewTrithemius() *Trithemius

func (*Trithemius) Decipher

func (t *Trithemius) Decipher(text string) string

Decipher deciphers string using Trithemius cipher.

func (*Trithemius) Encipher

func (t *Trithemius) Encipher(text string) string

Encipher enciphers string using Trithemius cipher.

type Vigenere

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

Vigenere is a Vigenère cipher key.

func NewVigenere

func NewVigenere(key []int8) *Vigenere

NewVigenere constructs a Vigenère cipher key.

func (*Vigenere) Decrypt

func (v *Vigenere) Decrypt(cipher string) string

Decrypt decrypts the plaintext with the Vigenère cipher.

func (*Vigenere) Encrypt

func (v *Vigenere) Encrypt(plain string) string

Encrypt encrypts the plaintext with the Vigenère cipher.

Jump to

Keyboard shortcuts

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