Add source files this time

This commit is contained in:
Smaug123
2016-01-03 21:43:29 +00:00
parent d0c4f0379e
commit 949816f7e0
8 changed files with 312 additions and 0 deletions

11
src/caesar.jl Normal file
View File

@@ -0,0 +1,11 @@
function encrypt_caesar(plaintext, key::Integer)
# plaintext: string; key: integer offset, so k=1 sends "a" to "b"
key = ((key-1) % 26) + 1
encrypt_monoalphabetic(plaintext, join([collect(Char(97+key):'z'); collect('a':Char(97+key-1))]))
end
function decrypt_caesar(ciphertext, key::Integer)
# ciphertext: string; key: integer offset, so k=1 decrypts "B" as "A"
key = ((key-1) % 26) + 1
encrypt_caesar(ciphertext, 26-key)
end