Jac*_*ies -4 c caesar-cipher cs50
构建了一个使用Caesar Cipher加密事物的C程序.它将它转换为字母数字(0 = a/1 = b/2 = c),然后在移动了使用模运算符指定的字符数后转换它.我目前正在尝试构建一个解密它的程序,我需要与模运算符完全相反的方法来反转序列.
如果要反转凯撒密码,则不需要寻找模运算符的反函数.
如果您的加密是
int encrypt(int plaintext, int shift){
int ciphertext = (plaintext + shift) % 26;
return ciphertext;
}
Run Code Online (Sandbox Code Playgroud)
然后解密就是
int decrypt(int ciphertext, int shift){
int plaintext = (ciphertext - shift + 26) % 26;
return plaintext;
}
Run Code Online (Sandbox Code Playgroud)
无论你选择什么shift加密.