mirror of
https://github.com/Smaug123/ClassicalCiphers.jl
synced 2025-10-12 04:48:39 +00:00
Add source files this time
This commit is contained in:
11
src/caesar.jl
Normal file
11
src/caesar.jl
Normal 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
|
Reference in New Issue
Block a user