22 lines
570 B
Text
22 lines
570 B
Text
enum type mode ENCRYPT = +1, DECRYPT = -1 end type
|
|
|
|
function Vigenere(string s, string key, mode m)
|
|
string res = ""
|
|
integer k = 1, ch
|
|
s = upper(s)
|
|
for i=1 to length(s) do
|
|
ch = s[i]
|
|
if ch>='A' and ch<='Z' then
|
|
res &= 'A'+mod(ch+m*(key[k]+26),26)
|
|
k = mod(k,length(key))+1
|
|
end if
|
|
end for
|
|
return res
|
|
end function
|
|
|
|
constant key = "LEMON",
|
|
s = "ATTACK AT DAWN",
|
|
e = Vigenere(s,key,ENCRYPT),
|
|
d = Vigenere(e,key,DECRYPT)
|
|
|
|
printf(1,"Original: %s\nEncrypted: %s\nDecrypted: %s\n",{s,e,d})
|