Add Affine functionality - encrypt, decrypt, crack

This commit is contained in:
Smaug123
2016-01-06 19:56:06 +00:00
parent 6eb59cde05
commit 6a6aa3d078
6 changed files with 122 additions and 1 deletions

22
test/affine.jl Normal file
View File

@@ -0,0 +1,22 @@
using ClassicalCiphers
using Base.Test
# docs examples
@test encrypt_affine("Hello, World!", 3, 4) == "ZQLLU, SUDLN!"
@test decrypt_affine("ZQLLU, SUDLN!", 3, 4) == "hello, world!"
@test crack_affine("zqllu, sudln!") == ((3, 4), "hello, world!")
# Wikipedia examples
@test encrypt_affine("affine cipher", 5, 8) == "IHHWVC SWFRCP"
@test decrypt_affine("IHHWVC SWFRCP", 5, 8) == "affine cipher"
# Practical Cryptography
@test encrypt_affine("defend the east wall of the castle", 5, 7) == uppercase("wbgbuw yqb bhty nhkk zg yqb rhtykb")
@test decrypt_affine("wbgbuwyqbbhtynhkkzgyqbrhtykb", 5, 7) == "defendtheeastwallofthecastle"
@test crack_affine("wbgbuwyqbbhtynhkkzgyqbrhtykb") == ((5, 7), "defendtheeastwallofthecastle")
@test crack_affine("wbgbuwyqbbhtynhkkzgyqbrhtykb", mult=5) == ((5, 7), "defendtheeastwallofthecastle")
@test crack_affine("wbgbuwyqbbhtynhkkzgyqbrhtykb", add=7) == ((5, 7), "defendtheeastwallofthecastle")

View File

@@ -1,6 +1,6 @@
using ClassicalCiphers
tests = ["vigenere", "monoalphabetic", "solitaire", "caesar", "portas"]
tests = ["vigenere", "monoalphabetic", "solitaire", "caesar", "portas", "affine"]
println("Running tests:")