33 lines
828 B
Plaintext
33 lines
828 B
Plaintext
import <Utilities/Sequence.sl>;
|
|
import <Utilities/Conversion.sl>;
|
|
|
|
lowerAlphabet := "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
upperAlphabet := "abcdefghijklmnopqrstuvwxyz";
|
|
|
|
caesarEncrypt(ch, key) :=
|
|
let
|
|
correctAlphabet :=
|
|
lowerAlphabet when some(ch = lowerAlphabet)
|
|
else
|
|
upperAlphabet;
|
|
|
|
index := Sequence::firstIndexOf(correctAlphabet, ch);
|
|
|
|
newIndex := (index + key - 1) mod 26 + 1;
|
|
in
|
|
ch when not(some(ch = lowerAlphabet) or some(ch = upperAlphabet))
|
|
else
|
|
correctAlphabet[newIndex];
|
|
|
|
caesarDecrypt(ch, key) := caesarEncrypt(ch, 26 - key);
|
|
|
|
main(args(2)) :=
|
|
let
|
|
key := Conversion::stringToInt(args[2]);
|
|
encrypted := caesarEncrypt(args[1], key);
|
|
decrypted := caesarDecrypt(encrypted, key);
|
|
in
|
|
"Input: \t" ++ args[1] ++ "\n" ++
|
|
"Encrypted:\t" ++ encrypted ++ "\n" ++
|
|
"Decrypted:\t" ++ decrypted;
|