Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
27
Task/Substitution-cipher/Sidef/substitution-cipher.sidef
Normal file
27
Task/Substitution-cipher/Sidef/substitution-cipher.sidef
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
module SubstitutionCipher {
|
||||
|
||||
const key = %c"]kYV}(!7P$n5_0i R:?jOWtF/=-pe'AD&@r6%ZXs\"v*N[#wSl9zq2^+g;LoB`aGh{3.HIu4fbK)mU8|dMET><,Qc\\C1yxJ"
|
||||
|
||||
func encode(String s) {
|
||||
var r = ""
|
||||
s.each {|c|
|
||||
r += key[c.ord - 32]
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func decode(String s) {
|
||||
var r = ""
|
||||
s.each {|c|
|
||||
r += (key.first_index { _ == c } + 32 -> chr)
|
||||
}
|
||||
return r
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
with ("The quick brown fox jumps over the lazy dog, who barks VERY loudly!") { |s|
|
||||
var enc = SubstitutionCipher::encode(s)
|
||||
var dec = SubstitutionCipher::decode(enc)
|
||||
say("Original: ", s, "\n -> Encoded: ", enc, "\n -> Decoded: ", dec)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue