cornsea

破解简单移位替代加密

简单移位替代加密,密钥一共有26种可能(0,...,25),循环解密,看解密后的明文就可以猜中密钥是多少。

python程序如下:

alphabet_table = 'abcdefghijklmnopqrstuvwxyz'
ciphertext  = 'irxuvfruhdqgvhyhqbhduvdir'
plaintext   = 'fourscoreandsevenyearsago'
ciphertext1 = 'csyevixivqmrexih'

#decrypt
for i in range(0,26):
    result =''
    for j in range(0,len(ciphertext1)):
        index = ord(ciphertext1[j]) - ord('a')
        index = (index - i) % len(alphabet_table)
        result += alphabet_table[index]
    print result

posted on 2010-06-19 22:47  cornsea  阅读(674)  评论(0编辑  收藏  举报

导航