RosettaCodeData/Task/Caesar-cipher/Astro/caesar-cipher.astro

14 lines
399 B
Text
Raw Permalink Normal View History

2017-09-23 10:01:46 +02:00
fun caesar(s, k, decode: false):
2018-08-17 15:15:24 +01:00
if decode:
k = 26 - k
2019-09-12 10:33:56 -07:00
result = ''
for i in s.uppercase() where 65 <= ord(i) <= 90:
result.push! char(ord(i) - 65 + k) mod 26 + 65
return result
2017-09-23 10:01:46 +02:00
2019-09-12 10:33:56 -07:00
let message = "The quick brown fox jumped over the lazy dogs"
let encrypted = caesar(msg, 11)
let decrypted = caesar(enc, 11, decode: true)
2018-08-17 15:15:24 +01:00
2019-09-12 10:33:56 -07:00
print(message, encrypted, decrypted, sep: '\n')