September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
22
Task/Vigen-re-cipher/Phix/vigen-re-cipher.phix
Normal file
22
Task/Vigen-re-cipher/Phix/vigen-re-cipher.phix
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
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})
|
||||
Loading…
Add table
Add a link
Reference in a new issue