Skip to content

bad-antics/CryptoAnalysis.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CryptoAnalysis.jl

Classical cryptanalysis and cipher-breaking toolkit for Julia.

Features

  • Frequency Analysis — single character, bigram, and trigram frequency distributions
  • Index of Coincidence — detect mono- vs polyalphabetic ciphers
  • Kasiski Examination — find repeated sequences to estimate key lengths
  • Caesar Cipher — encrypt, decrypt, and automatic breaking via frequency analysis
  • Vigenère Cipher — encrypt, decrypt, and automatic breaking via IoC + column analysis
  • XOR Analysis — single-byte and repeating-key XOR breaking with Hamming distance key length detection
  • Shannon Entropy — measure randomness of text and byte data
  • Chi-Squared Test — statistical comparison against English letter frequencies
  • Hamming Distance — bitwise distance between byte sequences and strings
  • English Scoring — score text for English-likeness using frequency correlation

Installation

using Pkg
Pkg.add("CryptoAnalysis")

Quick Start

using CryptoAnalysis

# Break a Caesar cipher
plaintext, shift = break_caesar("KHOOR ZRUOG")
# ("HELLO WORLD", 3)

# Encrypt / decrypt with Vigenère
ct = vigenere_encrypt("ATTACK AT DAWN", "LEMON")
vigenere_decrypt(ct, "LEMON")

# Analyze letter frequencies
freq = frequency("The quick brown fox")

# Calculate entropy
e = entropy("some ciphertext")

# Index of coincidence
ic = index_of_coincidence("THEQUICKBROWNFOX")

# Break single-byte XOR
data = xor_encrypt(Vector{UInt8}("secret message"), UInt8[0x42])
recovered, key_byte, score = break_single_byte_xor(data)

# Chi-squared test against English
chi_squared_test("This is English text")

# Hamming distance
hamming_distance("this is a test", "wokka wokka!!!")  # 37

API Reference

Function Description
frequency(text) Letter frequency distribution
bigram_frequency(text) Bigram frequency distribution
trigram_frequency(text) Trigram frequency distribution
index_of_coincidence(text) Probability two random letters match
kasiski_examination(text) Find repeated substrings and factor distances
detect_key_length(text) IoC-based polyalphabetic key length detection
caesar_encrypt(text, shift) Caesar cipher encryption
caesar_decrypt(text, shift) Caesar cipher decryption
break_caesar(ciphertext) Automatic Caesar cipher breaking
vigenere_encrypt(text, key) Vigenère cipher encryption
vigenere_decrypt(text, key) Vigenère cipher decryption
break_vigenere(ciphertext) Automatic Vigenère cipher breaking
xor_encrypt(data, key) XOR encryption with repeating key
xor_decrypt(data, key) XOR decryption (same as encrypt)
break_single_byte_xor(data) Break single-byte XOR cipher
break_repeating_key_xor(data) Break repeating-key XOR cipher
entropy(text) Shannon entropy in bits
chi_squared(observed, expected) Chi-squared statistic
chi_squared_test(text) Chi-squared test against English frequencies
hamming_distance(a, b) Bitwise Hamming distance
english_score(text) English-likeness score
is_likely_english(text) Boolean English detection
letter_only(text) Strip non-letters, uppercase

License

MIT

About

Classical cryptanalysis and cipher-breaking toolkit for Julia — frequency analysis, Kasiski, Vigenere/Caesar breaking, entropy, XOR analysis

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages