Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
35
Task/Caesar-cipher/Nanoquery/caesar-cipher.nanoquery
Normal file
35
Task/Caesar-cipher/Nanoquery/caesar-cipher.nanoquery
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
def caesar_encode(plaintext, shift)
|
||||
uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
lowercase = "abcdefghijklmnopqrstuvwxyz"
|
||||
|
||||
cipher = ""
|
||||
for char in plaintext
|
||||
if char in uppercase
|
||||
cipher += uppercase[uppercase[char] - (26 - shift)]
|
||||
else if char in lowercase
|
||||
cipher += lowercase[lowercase[char] - (26 - shift)]
|
||||
else
|
||||
cipher += char
|
||||
end
|
||||
end
|
||||
|
||||
return cipher
|
||||
end
|
||||
|
||||
def caesar_decode(cipher, shift)
|
||||
uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
lowercase = "abcdefghijklmnopqrstuvwxyz"
|
||||
|
||||
plaintext = ""
|
||||
for char in cipher
|
||||
if char in uppercase
|
||||
plaintext += uppercase[uppercase[char] - shift]
|
||||
else if char in lowercase
|
||||
plaintext += lowercase[lowercase[char] - shift]
|
||||
else
|
||||
plaintext += char
|
||||
end
|
||||
end
|
||||
|
||||
return plaintext
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue