diff --git a/test/affine.jl b/test/affine.jl index 006f462..f8d3623 100644 --- a/test/affine.jl +++ b/test/affine.jl @@ -1,6 +1,3 @@ -using ClassicalCiphers -using Test - # docs examples @test encrypt_affine("Hello, World!", 3, 4) == "ZQLLU, SUDLN!" @@ -19,4 +16,4 @@ using Test @test crack_affine("wbgbuwyqbbhtynhkkzgyqbrhtykb") == ("defendtheeastwallofthecastle", (5, 7)) @test crack_affine("wbgbuwyqbbhtynhkkzgyqbrhtykb", mult=5) == ("defendtheeastwallofthecastle", (5, 7)) -@test crack_affine("wbgbuwyqbbhtynhkkzgyqbrhtykb", add=7) == ("defendtheeastwallofthecastle", (5, 7)) \ No newline at end of file +@test crack_affine("wbgbuwyqbbhtynhkkzgyqbrhtykb", add=7) == ("defendtheeastwallofthecastle", (5, 7)) diff --git a/test/caesar.jl b/test/caesar.jl index b34d91c..bdccf08 100644 --- a/test/caesar.jl +++ b/test/caesar.jl @@ -1,6 +1,3 @@ -using ClassicalCiphers -using Test - @test encrypt_caesar("This code was not strictly invented by Julius Caesar, but it was reported by Roman historian Suetonius that Caesar used it, and hence the cipher was named.", 3) == "WKLV FRGH ZDV QRW VWULFWOB LQYHQWHG EB MXOLXV FDHVDU, EXW LW ZDV UHSRUWHG EB URPDQ KLVWRULDQ VXHWRQLXV WKDW FDHVDU XVHG LW, DQG KHQFH WKH FLSKHU ZDV QDPHG." @test encrypt_caesar("The Caesar cipher was traditionally used by shifting each letter exactly three positions down.") == "WKH FDHVDU FLSKHU ZDV WUDGLWLRQDOOB XVHG EB VKLIWLQJ HDFK OHWWHU HADFWOB WKUHH SRVLWLRQV GRZQ." diff --git a/test/enigma.jl b/test/enigma.jl index 331a9d5..d63d1f9 100644 --- a/test/enigma.jl +++ b/test/enigma.jl @@ -1,6 +1,3 @@ -using ClassicalCiphers -using Test - @test (encrypt_enigma("AAA", [1,2,3], "AAA") == "BDZ") @test (decrypt_enigma("BDZ", [1,2,3], "AAA") == "aaa") diff --git a/test/hill.jl b/test/hill.jl index 04d1f2c..7b00bf6 100644 --- a/test/hill.jl +++ b/test/hill.jl @@ -1,6 +1,3 @@ -using ClassicalCiphers -using Test - # Wikipedia examples @test encrypt_hill("help!", [3 3; 2 5]) == "HIAT" @@ -25,4 +22,4 @@ using Test @test encrypt_hill("att", [2 4 5; 9 2 1; 3 17 7]) == "PFO" @test encrypt_hill("the gold is buried in orono", [5 17; 4 15]) == uppercase("gzscxnvcdjzxeovcrclsrc") -@test decrypt_hill("gzscxnvcdjzxeovcrclsrc", [5 17; 4 15]) == "thegoldisburiedinorono" \ No newline at end of file +@test decrypt_hill("gzscxnvcdjzxeovcrclsrc", [5 17; 4 15]) == "thegoldisburiedinorono" diff --git a/test/monoalphabetic.jl b/test/monoalphabetic.jl index 58a4a2a..7686e65 100644 --- a/test/monoalphabetic.jl +++ b/test/monoalphabetic.jl @@ -1,5 +1,4 @@ -using ClassicalCiphers -using Test +# Patrick's tests: @test encrypt_monoalphabetic("aBcbD", Dict{Char, Char}('a' => '5', 'B' => '@', 'b' => 'o', 'D' => 'D')) == "5@coD" @@ -9,4 +8,26 @@ using Test @test decrypt_monoalphabetic("5@coD", Dict{Char, Char}('a' => '5', 'B' => '@', 'b' => 'o', 'D' => 'D')) == "aBcbD" @test decrypt_monoalphabetic("WKLV FRGH ZDV LQYHQWHG EB MXOLXV FDHVDU", "DEFGHIJKLMNOPQRSTUVWXYZABC") == lowercase("THIS CODE WAS INVENTED BY JULIUS CAESAR") + + +# Jake's tests: + +@test encrypt_monoalphabetic("hello this is plaintext", "abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz") == "HELLO THIS IS PLAINTEXT" +@test encrypt_monoalphabetic("hello this is plaintext", "abcdefghijklmnopqrstuvwxyz") == "HELLO THIS IS PLAINTEXT" +@test encrypt_monoalphabetic("hello this is plaintext", "abcdefghijklmnopqrstuvwxyz", "qwertyuiopasdfghjklzxcvbnm") == "ITSSG ZIOL OL HSQOFZTBZ" +@test encrypt_monoalphabetic("hello this is plaintext", "qwertyuiopasdfghjklzxcvbnm", "abcdefghijklmnopqrstuvwxyz") == "PCSSI EPHL HL JSKHYECUE" +@test encrypt_monoalphabetic("ITSSG ZIOL OL HSQOFZTBZ", "qwertyuiopasdfghjklzxcvbnm", "abcdefghijklmnopqrstuvwxyz") == "HELLO THIS IS PLAINTEXT" +@test encrypt_monoalphabetic("ITSSG ZIOL OL HSQOFZTBZ", "qwertyuiopasdfghjklzxcvbnm", "abcdefghijklmnopqrstuvwxyz") != encrypt_monoalphabetic("ITSSG ZIOL OL HSQOFZTBZ", "abcdefghijklmnopqrstuvwxyz", "qwertyuiopasdfghjklzxcvbnm") +@test encrypt_monoalphabetic("hello this is plaintext", Dict('n' => 'y','f' => 'n','w' => 'b','d' => 'm','e' => 'c','o' => 'i','h' => 'p','y' => 'f','i' => 'h','r' => 'd','t' => 'e','s' => 'l','j' => 'q','q' => 'a','k' => 'r','a' => 'k','c' => 'v','p' => 'j','m' => 'z','z' => 't','g' => 'o','x' => 'u','u' => 'g','l' => 's','v' => 'w','b' => 'x')) == "pcssi ephl hl jskhyecue" +@test encrypt_monoalphabetic("hello this is plaintext", Dict('n' => 'f','f' => 'y','w' => 'v','d' => 'r','e' => 't','o' => 'g','h' => 'i','j' => 'p','i' => 'o','k' => 'a','r' => 'k','s' => 'l','t' => 'z','q' => 'j','y' => 'n','a' => 'q','c' => 'e','p' => 'h','m' => 'd','z' => 'm','g' => 'u','v' => 'c','l' => 's','u' => 'x','x' => 'b','b' => 'w')) == "itssg ziol ol hsqofztbz" +@test decrypt_monoalphabetic("hello this is ciphertext", "abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz") == "hello this is ciphertext" +@test decrypt_monoalphabetic("hello this is ciphertext", "abcdefghijklmnopqrstuvwxyz") == "hello this is ciphertext" +@test decrypt_monoalphabetic("hello this is ciphertext", "abcdefghijklmnopqrstuvwxyz"; reverse_dict = true) == "hello this is ciphertext" +@test decrypt_monoalphabetic("hello this is ciphertext", "qwertyuiopasdfghjklzxcvbnm", "abcdefghijklmnopqrstuvwxyz") == "itssg ziol ol eohitkztbz" +@test decrypt_monoalphabetic("hello this is ciphertext", "qwertyuiopasdfghjklzxcvbnm", "abcdefghijklmnopqrstuvwxyz"; reverse_dict = false) == "pcssi ephl hl vhjpcdecue" +@test decrypt_monoalphabetic("ITSSG ZIOL OL HSQOFZTBZ", "abcdefghijklmnopqrstuvwxyz", "qwertyuiopasdfghjklzxcvbnm"; reverse_dict = false) == "ozllu mogs gs iljgymzwm" +@test decrypt_monoalphabetic("ITSSG ZIOL OL HSQOFZTBZ", "abcdefghijklmnopqrstuvwxyz", "qwertyuiopasdfghjklzxcvbnm"; reverse_dict = true) == "hello this is plaintext" +@test decrypt_monoalphabetic("PCSSI EPHL HL JSKHYECUE", "qwertyuiopasdfghjklzxcvbnm", "abcdefghijklmnopqrstuvwxyz"; reverse_dict = false) == "jvllh cjps ps qlrpfcvgc" +@test decrypt_monoalphabetic("PCSSI EPHL HL JSKHYECUE", "qwertyuiopasdfghjklzxcvbnm", "abcdefghijklmnopqrstuvwxyz"; reverse_dict = true) == "hello this is plaintext" +@test decrypt_monoalphabetic("ITSSG ZIOL OL HSQOFZTBZ", "abcdefghijklmnopqrstuvwxyz", "qwertyuiopasdfghjklzxcvbnm"; reverse_dict = false) != decrypt_monoalphabetic("ITSSG ZIOL OL HSQOFZTBZ", "abcdefghijklmnopqrstuvwxyz", "qwertyuiopasdfghjklzxcvbnm"; reverse_dict = true) diff --git a/test/playfair.jl b/test/playfair.jl index 98a36d1..57ece1d 100644 --- a/test/playfair.jl +++ b/test/playfair.jl @@ -1,6 +1,3 @@ -using ClassicalCiphers -using Test - # Wikipedia example @test encrypt_playfair("Hide the gold in the tree stump", "playfair example") == "BMODZBXDNABEKUDMUIXMMOUVIF" @@ -23,4 +20,4 @@ using Test @test (arr = ['P' 'L' 'A' 'Y' 'F'; 'I' 'R' 'E' 'X' 'M'; 'B' 'C' 'D' 'G' 'H'; 'K' 'N' 'O' 'Q' 'S'; 'T' 'U' 'V' 'W' 'Z']; decrypt_playfair("DMYRANVQCRGE", arr) == "helxloworldx") @test decrypt_playfair("GDDOGDRQARKYGDHDNKPRDAMSOGUPGKICQY", "charles") == "meetmeathamxmersmithbridgetonightx" -@test decrypt_playfair("BMODZBXDNABEKUDMUIXMMOUVIF", "playfair example") == "hidethegoldinthetrexestump" \ No newline at end of file +@test decrypt_playfair("BMODZBXDNABEKUDMUIXMMOUVIF", "playfair example") == "hidethegoldinthetrexestump" diff --git a/test/portas.jl b/test/portas.jl index 6cbd634..4c770cd 100644 --- a/test/portas.jl +++ b/test/portas.jl @@ -1,6 +1,3 @@ -using ClassicalCiphers -using Test - @test encrypt_portas("DEFENDTHEEASTWALLOFTHECASTLE", "FORTIFICATION") == uppercase("synnjscvrnrlahutukucvryrlany") @test decrypt_portas("synnjscvrnrlahutukucvryrlany", "FORTIFICATION") == lowercase("DEFENDTHEEASTWALLOFTHECASTLE") @@ -9,4 +6,4 @@ using Test # doc tests @test decrypt_portas("URYYB, JBEYQ!", "ab") == "hello, world!" -@test encrypt_portas("Hello, World!", "ab") == "URYYB, JBEYQ!" \ No newline at end of file +@test encrypt_portas("Hello, World!", "ab") == "URYYB, JBEYQ!" diff --git a/test/railfence.jl b/test/railfence.jl index dc034d5..d1aece2 100644 --- a/test/railfence.jl +++ b/test/railfence.jl @@ -1,6 +1,3 @@ -# using ClassicalCiphers -# using Test - @test encrypt_railfence("WE ARE DISCOVERED. FLEE AT ONCE", 3) == "WECRFACERDSOEE.LETNEAIVDEO" @test decrypt_railfence("WECRFACERDSOEE.LETNEAIVDEO", 3) == "wearediscovered.fleeatonce" @test encrypt_railfence("Julia is strong", 10) == "JULIAISGSNTOR" diff --git a/test/runtests.jl b/test/runtests.jl index 92f173b..23b7857 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,4 @@ -using ClassicalCiphers +include(joinpath(dirname(@__DIR__), "src", "ClassicalCiphers.jl")); using .ClassicalCiphers using Test tests = [ @@ -12,7 +12,6 @@ tests = [ "hill", "solitaire", "railfence", - "substitution" ] println("Running tests:") diff --git a/test/solitaire.jl b/test/solitaire.jl index 1d5999b..9b8cff7 100644 --- a/test/solitaire.jl +++ b/test/solitaire.jl @@ -1,6 +1,3 @@ -using ClassicalCiphers -using Test - @test encrypt_solitaire("aaaaaaaaaaaaaaa", "") == "EXKYIZSGEHUNTIQ" @test encrypt_solitaire("aaaaaaaaaaaaaaa", "f") == "XYIUQBMHKKJBEGY" @test encrypt_solitaire("AAAAAAAAAAAAAAA", "fo") == "TUJYMBERLGXNDIW" diff --git a/test/vigenere.jl b/test/vigenere.jl index bd40cd1..e525b70 100644 --- a/test/vigenere.jl +++ b/test/vigenere.jl @@ -1,6 +1,3 @@ -using ClassicalCiphers -using Test - # doc examples @test encrypt_vigenere("ab", [0, 1]) == "AC" @test decrypt_vigenere("ac", [0, 1]) == "ab" @@ -36,4 +33,4 @@ LESTCOMIQUEETLAIDLUNAGACESONBECAVECUNBRULEGUEULELAUTREMIMEENBOITANTLIN FIRMEQUIVOLAITLEPOETEESTSEMBLABLEAUPRINCEDESNUEESQUIHANTELATEMPETEETSE RITDELARCHERBAUDELAIREEXILESURLESOLAUMILIEUDESHUEESLEMOTPOURETAGEQUATR EESTTRAJANSESAILESDEGEANTLEMPECHENTDEMARCHER"; -crack_vigenere(singh) == ("SCUBA", lowercase(ClassicalCiphers.letters_only(singh_ans)))) \ No newline at end of file +crack_vigenere(singh) == ("SCUBA", lowercase(ClassicalCiphers.letters_only(singh_ans))))