cryptopals

package module
v0.0.0-...-f332d2d Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2017 License: MIT Imports: 6 Imported by: 0

README

Documentation Build Status Go Report Card

Solutions to the cryptopals crypto challenges.

I have optimised for code legibility over efficiency. I have also used code comments, where I would normally use commit messages, to give more context to the code.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64Decode

func Base64Decode(text []byte) ([]byte, error)

Base64Decode decodes a base64 byte slice into an byte slice

func Base64Encode

func Base64Encode(text []byte) []byte

Base64Encode encodes a byte slice into a base64 byte slice

func DecryptAESECB

func DecryptAESECB(text, key []byte) ([]byte, error)

DecryptAESECB decrypts some text that has been encrypted with AES in ECB mode.

func DetectECB

func DetectECB(text []byte) bool

DetectECB detects whether a byte slice has been encrypted in ECB mode by seeing if it has repeating blocks of data.

func FixedKeyXOR

func FixedKeyXOR(text, key []byte) ([]byte, error)

FixedKeyXOR encrypts some text against a key of the same size.

func GuessXORKeySize

func GuessXORKeySize(text []byte) ([]int, error)

GuessXORKeySize guesses the most likely key size for some XORed text. The results are sorted in order of probability.

func HammingDistance

func HammingDistance(one, two []byte) (int, error)

HammingDistance returns the number of differences between two byte slices: https://en.wikipedia.org/wiki/Hamming_distance

func HexDecode

func HexDecode(text []byte) ([]byte, error)

HexDecode decodes a hexadecimal byte slice to a decimal byte slice

func HexEncode

func HexEncode(text []byte) []byte

Encodes a decimal byte slice to a hexadecimal byte slice

func HexToBase64

func HexToBase64(text []byte) ([]byte, error)

HexToBase64 converts hexadecimal encoded text to base64.

func PKCS7Padding

func PKCS7Padding(text []byte, blockSize int) []byte

PKCS7Padding adds PKCS#7 padding to a byte slice. https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7

func PKCS7PaddingStrip

func PKCS7PaddingStrip(text []byte, blockSize int) []byte

PKCS7PaddingStrip strips PKCS#7 padding from a byte slice. https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7

func RepeatingKeyXOR

func RepeatingKeyXOR(text, key []byte) ([]byte, error)

RepeatingKeyXOR encrypts some text against a repeating key of a smaller size.

func ScoreEnglish

func ScoreEnglish(text []byte) int

ScoreEnglish returns a score indicating the likelihood that a string is comprised of English words by counting the most commonly occurring letters in the English language.

func StripBytes

func StripBytes(s []byte, c byte) []byte

StripBytes removes all occurrences of a byte from a byte slice.

func TransposeBlocks

func TransposeBlocks(in []byte, size int) [][]byte

TransposeBlocks divides the input into blocks of size and returns a slice of byte slices, the first containining the first byte from each block, the second containing the second byte for each block, etc.

Types

type KeyScore

type KeyScore struct {
	Score     int
	Key, Text []byte
}

KeyScore can be used to keep track of the most likely key.

func BruteForceMultiByteXOR

func BruteForceMultiByteXOR(text []byte) (KeyScore, error)

BruteForceMultiByteXOR finds the multi byte key that some text has been XORed against.

func BruteForceSingleByteXOR

func BruteForceSingleByteXOR(text []byte) (KeyScore, error)

BruteForceSingleByteXOR finds the single byte key that some text has been XORed against.

type KeySize

type KeySize struct {
	Size               int
	NoramlisedDistance float64
}

KeySize can be used to keep track of the most likely key size.

Jump to

Keyboard shortcuts

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