Documentation ¶
Index ¶
- Variables
- func A(n int) []byte
- func AlphaBytes(orig []byte) []byte
- func B(n int) []byte
- func BlockSizeECB(f EncryptFunc) int
- func BlockString(b []byte, bs int) string
- func ByteFreqs(counts [256]int) [256]float64
- func CountBytes(buf []byte) [256]int
- func DecryptAES(enc, key, iv []byte) []byte
- func DiffByteFreqs(a, b [256]float64) float64
- func EncryptAES(b, key, iv []byte) []byte
- func FirstModBlock(f EncryptFunc, bs int) int
- func FixedLen(f EncryptFunc, bs int) int
- func HMACSHA1(msg, key []byte) []byte
- func Hamming(a, b []byte) int
- func MDPadding(mlen int, bo binary.ByteOrder) []byte
- func NextSuffixByteECB(f EncryptFunc, bs int, known []byte) byte
- func PadPKCS7(b []byte, bs int) []byte
- func PrefixLen(f EncryptFunc, bs int) int
- func RandBytes(n int) []byte
- func RandInt(max int) int
- func RandInt64(max int64) int64
- func RandWord() (word string, maxLen int)
- func ReadBase64(p string) []byte
- func ReadBase64Lines(p string) [][]byte
- func ReadHexLines(p string) [][]byte
- func SingleByteXOR(enc []byte) byte
- func SuffixLen(f EncryptFunc, bs int) int
- func Unhex(s string) []byte
- func UnpadPKCS7(b []byte) ([]byte, error)
- func UpperBytes(orig []byte) []byte
- func XOR(a, b []byte) []byte
- type CTR
- type EncryptFunc
- type MT
- type MTParams
- type Score
Constants ¶
This section is empty.
Variables ¶
var EnglishUpperFreqs [256]float64
EnglishUpperFreqs contains relative frequencies of 'A' through 'Z' in English words. All other bytes are 0.
Functions ¶
func AlphaBytes ¶
AlphaBytes returns a buffer containing only ASCII letters from orig.
func BlockSizeECB ¶
func BlockSizeECB(f EncryptFunc) int
BlockSizeECB infers the block size used by f, an ECB function.
func BlockString ¶
BlockString returns a hex representation of b segmented into blocks.
func ByteFreqs ¶
ByteFreqs returns a table of normalized frequencies in [0.0, 1.0] of bytes with the supplied counts.
func CountBytes ¶
CountBytes returns an array containing the number of times each byte occurs in buf.
func DecryptAES ¶
DecryptAES decrypts b using AES-128 with the supplied key. If iv is non-nil CBC mode is used; otherwise ECB is used.
func DiffByteFreqs ¶
DiffByteFreqs characterizes byte frequency differences between a and b. The frequency distributions should each be normalized to sum to 1 (see ByteFreqs).
func EncryptAES ¶
EncryptAES encrypts b using AES-128 with the supplied key. If iv is non-nil CBC mode is used; otherwise ECB is used.
func FirstModBlock ¶
func FirstModBlock(f EncryptFunc, bs int) int
FirstModBlock returns the index of the first modifiable block for f, an ECB or CBC function with a fixed key and fixed prefix.
func FixedLen ¶
func FixedLen(f EncryptFunc, bs int) int
FixedLen returns the combined length of a fixed prefix and suffix used by f, an ECB or CBC function with a fixed key.
func HMACSHA1 ¶
HMACSHA1 implements HMAC as described at https://en.wikipedia.org/wiki/HMAC#Implementation using SHA-1 as its hash function.
func Hamming ¶
Hamming returns the Hamming distance (i.e. number of differing bits) between a and b, which must be of the same length.
func MDPadding ¶
MDPadding computes SHA-1, MD4, etc. padding for a message of length mlen *bytes*. bo specifies the byte order used when appending the length (SHA-1 uses big-endian, while MD4 uses little-endian).
Pseudocode from https://en.wikipedia.org/wiki/SHA-1#SHA-1_pseudocode:
append the bit '1' to the message e.g. by adding 0x80 if message length is a multiple of 8 bits. append 0 ≤ k < 512 bits '0', such that the resulting message length in bits is congruent to −64 ≡ 448 (mod 512) append ml, the original message length, as a 64-bit big-endian integer. Thus, the total length is a multiple of 512 bits.
func NextSuffixByteECB ¶
func NextSuffixByteECB(f EncryptFunc, bs int, known []byte) byte
NextSuffixByteECB attacks f to find the next byte in a fixed suffix. The bytes decoded so far should be passed in known. f should not use a fixed prefix.
func PadPKCS7 ¶
PadPKCS7 returns a new buffer containing b padded to the supplied block size using PKCS#7 padding.
func PrefixLen ¶
func PrefixLen(f EncryptFunc, bs int) int
PrefixLen returns the length of the fixed prefix used by f, an ECB or CBC function with a fixed key.
func RandWord ¶
RandWord returns a randomly-chosen word from /usr/share/dict/words. The maximum length of all words is also returned.
func ReadBase64 ¶
ReadBase64 reads base64 data from the file at p. It panics on error.
func ReadBase64Lines ¶
ReadHexLines reads and decodes base64 lines from p.
func ReadHexLines ¶
ReadHexLines reads and decodes hex lines from p.
func SingleByteXOR ¶
SingleByteXOR tries to find the byte that's most likely to have been used for single-byte XOR encryption of English text.
func SuffixLen ¶
func SuffixLen(f EncryptFunc, bs int) int
SuffixLen returns the length of the fixed suffix used by f, an ECB or CBC function with a fixed key.
func UnpadPKCS7 ¶
UnpadPKCS7 undoes padding added by PadPKCS7.
func UpperBytes ¶
UpperBytes returns a buffer where lowercase ASCII letters in orig are uppercased. All other bytes are unchanged.
Types ¶
type CTR ¶
type CTR struct {
// contains filtered or unexported fields
}
CTR implements AES in CTR mode.
type EncryptFunc ¶
EncryptFunc encrypts the supplied buffer. An additional prefix and/or suffix may be applied. The same prefix, suffix, and key are used every time.
type MT ¶
type MT struct {
// contains filtered or unexported fields
}
MT is a PRNG implementing the Mersenne Twister algorithm. See https://en.wikipedia.org/wiki/Mersenne_Twister for details and pseudocode.
func NewMT19937 ¶
NewMT19937 returns a new MT using the Mersenne prime 2^19937−1.
type MTParams ¶
type MTParams struct { W int // word size (in number of bits) N int // degree of recurrence M int // middle word, an offset used in the recurrence relation defining the series x, 1 ≤ m < n A uint64 // coefficients of the rational normal form twist matrix B, C uint64 // TGFSR(R) tempering bitmasks D uint64 // additional Mersenne Twister tempering bitmask R int // separation point of one word, or the number of bits of the lower bitmask, 0 ≤ r ≤ w - 1 S, T int // TGFSR(R) tempering bit shifts U, L int // additional Mersenne Twister tempering bit shifts F uint64 // "another parameter to the generator, though not part of the algorithm proper" WMask uint64 // mask for bottom w bits }
Parameter values are listed at https://en.wikipedia.org/wiki/Mersenne_Twister.