RosettaCodeData/Task/Caesar-cipher/Ursa/caesar-cipher.ursa

29 lines
679 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
decl string mode
while (not (or (= mode "encode") (= mode "decode")))
2026-02-01 16:33:20 -08:00
out "encode/decode: " console
set mode (lower (in string console))
2023-07-01 11:58:00 -04:00
end while
decl string message
out "message: " console
set message (upper (in string console))
decl int key
out "key: " console
set key (in int console)
if (or (> key 26) (< key 0))
2026-02-01 16:33:20 -08:00
out endl "invalid key" endl console
stop
2023-07-01 11:58:00 -04:00
end if
if (= mode "decode")
2026-02-01 16:33:20 -08:00
set key (int (- 26 key))
2023-07-01 11:58:00 -04:00
end if
for (decl int i) (< i (size message)) (inc i)
2026-02-01 16:33:20 -08:00
if (and (> (ord message<i>) 64) (< (ord message<i>) 91))
out (chr (int (+ (mod (int (+ (- (ord message<i>) 65) key)) 26) 65))) console
end if
2023-07-01 11:58:00 -04:00
end for
out endl console