首页 > 编程知识 正文

凯撒密码怎么求位移数,凯撒密码是方法被称为循环移位

时间:2023-05-06 15:09:11 阅读:250355 作者:3773

可靠的草丛密码问题:通过把字母移动一定的位数来实现加密和解密。 可靠的草丛密码说明代码结果

可靠的草丛密码说明

例如(移动3格):a-D、b-E、 c-F、d-G、e-H … … s-V … …、z-C
明文:access control
可变为: DFFHVV FRQWURO

代码 import randomdef Letter_num(Letter): # a-z转换为0-25 return ord(Letter) - 97def num_Letter(num): # 0-25转换为a-z return chr(num + 97)def encryption_Letter(P, K): # 加密单个字母 C = num_Letter((Letter_num(P) + K) % 26) return Cdef Decrypt_Letter(C, K): # 解密单个字母 P = num_Letter((Letter_num(C) - K) % 26) return Pdef encryption_fun(P_char, K): # 加密字符串 C_char = '' for P in P_char: if P.isalpha(): P = encryption_Letter(P, K) C_char = C_char + P return C_chardef Decrypt_fun(C_char, K): # 解密字符串 P_char = '' for C in C_char: if C.isalpha(): C = Decrypt_Letter(C, K) P_char = P_char + C return P_charif __name__ == '__main__': K = int(random.random()*26%26) P_text = "let's meet after the party.if you understand this sentence, the program runs successfully.abcd efghjgkl mnopqr stu vwxy z" print('原文为:',P_text) print('K:',K) C_text = encryption_fun(P_text, K) print('密文为:', C_text) PP_text = Decrypt_fun(C_text, K) print('解密后是:', PP_text) 结果 原文为: let's meet after the party.if you understand this sentence, the program runs successfully.abcd efghjgkl mnopqr stu vwxy zK: 14密文为: zsh'g assh othsf hvs dofhm.wt mci ibrsfghobr hvwg gsbhsbqs, hvs dfcufoa fibg giqqsggtizzm.opqr stuvxuyz abcdef ghi jklm n解密后是: let's meet after the party.if you understand this sentence, the program runs successfully.abcd efghjgkl mnopqr stu vwxy z
阿诺德渲染器gpu需要学习么?

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。