我使用python2.7.12运行这个程序
charset="ABCDEFGHIJKLMNOPQRSTUVWXYZ" # The list of characters to be encrypted
numchars=len(charset) # number of characters that are in the list for encryption
def caesar_crack(crackme,i,newkey):
print '[*] CRACKING - key: %d; ciphertext: %s' % (i,crackme)
crackme=crackme.upper()
plaintext='' #initialise plaintext as an empty string
while i <= 26:
for ch in crackme: #'for' will check each character in plaintext against charset
if ch in charset:
pos=charset.find(ch) #finds the position of the current character
pos=pos-newkey
else:
new='' # do nothing with characters not in charet
if pos>=len(charset): #if the pos of the character is more or equal to the charset e.g -22 it will add 26 to get the correct letter positioning/value
pos=pos+26
else:
new=charset[pos]
plaintext=plaintext+new
print '[*] plaintext: ' + plaintext
if i <= 27:
newkey=newkey+1
i=i+1
return plaintext
def main():
# test cases
newkey=0
i=0
crackme = 'PBATENGHYNGVBAFLBHUNIRPENPXRQGURPBQRNAQGURFUVSGJNFGUVEGRRA'
# call functions with text cases
caesar_crack(crackme,i,newkey)
# boilerplate
if __name__ == '__main__':
main()
这就是我到目前为止所拥有的,我目前正在寻找让它循环多次,最好是26次(字母表中每个数字/字母1次)。你知道吗
我觉得我所拥有的应该可以很好地工作,但是我几乎可以肯定,我拥有的应该可以工作,但是在运行时它只会运行一次,例如newkey = 0
和i = 0
,但是会增加到下一个值newkey = 1
和i = 1
,但是不会重新运行。你知道吗
有人能发现我遗漏的致命缺陷吗?或任何关于如何使其运行更有效的提示,都将不胜感激。你知道吗
只需移动
向左一步
这将解决循环问题,它将通过所有26个数字
没有检查程序的剩余部分是否良好
相关问题 更多 >
编程相关推荐