Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/Substitution-cipher/Julia/substitution-cipher-1.julia
Normal file
23
Task/Substitution-cipher/Julia/substitution-cipher-1.julia
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
module SubstitutionCiphers
|
||||
|
||||
using Compat
|
||||
|
||||
const key = "]kYV}(!7P\$n5_0i R:?jOWtF/=-pe'AD&@r6%ZXs\"v*N[#wSl9zq2^+g;LoB`aGh{3.HIu4fbK)mU8|dMET><,Qc\\C1yxJ"
|
||||
|
||||
function encode(s::AbstractString)
|
||||
buf = IOBuffer()
|
||||
for c in s
|
||||
print(buf, key[Int(c) - 31])
|
||||
end
|
||||
return String(take!(buf))
|
||||
end
|
||||
|
||||
function decode(s::AbstractString)
|
||||
buf = IOBuffer()
|
||||
for c in s
|
||||
print(buf, Char(findfirst(==(c), key) + 31))
|
||||
end
|
||||
return String(take!(buf))
|
||||
end
|
||||
|
||||
end # module SubstitutionCiphers
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
let s = "The quick brown fox jumps over the lazy dog, who barks VERY loudly!"
|
||||
enc = SubstitutionCiphers.encode(s)
|
||||
dec = SubstitutionCiphers.decode(enc)
|
||||
println("Original: ", s, "\n -> Encoded: ", enc, "\n -> Decoded: ", dec)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue