Program Cipher:=
{
//加密子进程
subroutine encryption(plaintext,key):=
{
(String)plaintext->(char[])plaintext->index(97)
/*ascII 编码 a 97 b 98
- “hello” -> {‘h’,‘e’,…} -> 102,120…
*…x,y,z,a,b,…
*/
//加密算法
(index+key-26)%122 index+key>122,0<=key<=26,97<=inex<=122
(index+key)%122 97<=index+key<=122,0<=key<=26,97<=inex<=122
//ASCII码索引->字符串(加密后的信息)
index->String(ciphertext)
}
//解密子进程
subroutine decryption(ciphertext,key):=
{ //字符串->字符数组->ASCII码索引
(String)ciphertext->(char[])plaintext->index
//解密算法
//...,y,z,a,b,c,....
(index-key+26)%122 index-key<97, 0<=key<=26,97<=inex<=122
(index-key)%122 97<=index-key<=122,0<=key<=26,97<=inex<=122
//ASCII码索引->字符串(解密后的信息)
index->String(plaintext)
}
main:main-program():=
{
//加密
encryption(plaintext,key); //offset
//解密
decryption(ciphertext,key);
}
}