私はこれは私がこれまで持っているものである2.7.12シーザー暗号割れは、Python
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()
この使ってPythonを実行しています、私は現在のループに複数回、これを取得するために探していますprefferably各数について26(1 /アルファベットの手紙)。
私はうまく動作するはず持っているものかのように感じるが、私は私が持っているが機能しなければならないことはほぼ確実だが、実行している時に、それは一度だけ例えばnewkey = 0
とi = 0
を実行しますが、次の値newkey = 1
とi = 1
に増加しますが、再実行されません。
誰かが私が行方不明の致命的欠陥を発見できますか?または、より効率的に動作させる方法についてのヒントもあります。
'should_restart'とは何ですか?それはどこにも使われていません。 –
ああ、私の悪い、私はそれを取ったと思った、編集は今反映する必要があります。 –