June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,18 +1,15 @@
|
|||
function rot(s::String, key::Integer)
|
||||
map(s) do c
|
||||
if 'a' <= c <= 'z'
|
||||
char( mod(c - 'a' + key, 26) + 'a')
|
||||
elseif 'A' <= c <= 'Z'
|
||||
char( mod(c - 'A' + key, 26) + 'A')
|
||||
else
|
||||
c
|
||||
end
|
||||
function rot(ch::Char, key::Integer)
|
||||
if key < 1 || key > 25 end
|
||||
if isalpha(ch)
|
||||
shft = ifelse(islower(ch), 'a', 'A')
|
||||
ch = (ch - shft + key) % 26 + shft
|
||||
end
|
||||
return ch
|
||||
end
|
||||
rot(str::AbstractString, key::Integer) = map(x -> rot(x, key), str)
|
||||
|
||||
msg = "The five boxing wizards jump quickly"
|
||||
key = 3
|
||||
txt = "The five boxing wizards jump quickly"
|
||||
invkey = 26 - 3
|
||||
|
||||
println("Original: ", txt);
|
||||
println("Encrypted: ", rot(txt, key))
|
||||
println("Decrypted: ", rot(rot(txt, key), 26 - key))
|
||||
println("# original: $msg\n encrypted: $(rot(msg, key))\n decrypted: $(rot(rot(msg, key), invkey))")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue