2016-03-03 28 views
0

我有問題暴力破解用RC4/ARC4加密的字符串的密鑰。Itarate密碼組合來查找字符串的密鑰

這是加密的字符串: E7Ev08_MEojYBixHRKTKQnRSC4hkriZ7XPsy3p4xAHUPj41Dlzu9

和字符串也被散列以BASE64,所以完整的編碼的字符串是: RTdFdjA4X01Fb2pZQml4SFJLVEtRblJTQzRoa3JpWjdYUHN5M3A0eEFIVVBqNDFEbHp1OQ==

#-*- coding: utf-8 -*- 
import threading 
import sys 
import time 
import re 
import itertools 
from itertools import product 
from Crypto.Cipher import ARC4 
import base64 


def special_match(strg): 
    try: 
    strg.decode('utf-8') 
    except UnicodeDecodeError: 
    pass 
    else: 
    print('\nkey found at %s, key: %s' % (time.ctime(), rc4_key)) 
    try: 
      f=open('key.txt','ab') 
      f.write('Key (%s): %s\n' % (time.ctime(), rc4_key)) 
      f.write('Decrypted string: ' + strg + '\n') 
      f.close() 
    except Exception as e: 
      print('ERROR WRITING KEY TO FILE: ' + str(e)) 

chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 
end_chars = chars[::-1][0:7] 

encoded_string = 'RTdFdjA4X01Fb2pZQml4SFJLVEtRblJTQzRoa3JpWjdYUHN5M3A0eEFIVVBqNDFEbHp1OQ==' 


spinner = itertools.cycle(['-', '/', '|', '\\']) 

while 1: 
     try: 
     # Iteration processess of possibel keys 
     for length in range(7,8): # only do length of 7 
      for attempt in itertools.permutations(chars, length): 
       rc4_key = ''.join(attempt) # This key is unknown, we are looking for it.. 
       Ckey = ARC4.new(rc4_key) 
       decoded = Ckey.decrypt(encoded_string.decode('base64')) 
       special_match(decoded) 

       sys.stdout.write(spinner.next()) # write the next character 
       sys.stdout.flush()    # flush stdout buffer (actual character display) 
       sys.stdout.write('\b')   # erase the last written char 

       # Exit the script when we have done all password-combination-iterations 
       if (rc4_key == end_chars): 
        print('iteration of combinations done! No key found.. :(\n' + time.ctime()) 
        exit() 

     except KeyboardInterrupt: 
     print('\nKeybord interrupt, exiting gracefully anyway on %s at %s' % (rc4_key, time.ctime())) 
     sys.exit() 

http://crypo.bz.ms/secure-rc4-online使用的加密字符串I'm和https://www.base64encode.org用UTF-8編碼。

問題

爲什麼我的腳本不能找到密鑰?

(IM沒有收到任何錯誤消息,則是更多,如果我錯過了在我的代碼的東西,或者這個問題的辦法的一般性問題。)

明文:This is something that I have encrypted,鍵:ABCFMSG

+0

不一致的壓痕可能會引發問題。 –

+0

如果提供正確的密鑰,解鎖是否會奏效? – JeD

+0

還有80億個可能的密鑰,可能需要很長很長的時間 – JeD

回答

0

好吧,似乎crypo.bz使用了一個真正奇怪的系統。基本上他們有一個非常奇怪的編碼,如果你只是使用他們的角色就會導致差異。

例如編碼「A」與鍵「A」應該產生的字符與值163

在十六進制A3。在crypo.bz中,我們會得到'oc'。

所以你有兩種可能性。要麼做一些密文分析,要麼使用其他網站。我推薦這個,因爲他們會告訴你在什麼它們編碼的結果:

http://www.fyneworks.com/encryption/RC4-Encryption/index.asp

以十六進制,並將其轉換爲字符串時,你應該能夠破譯它

您的代碼似乎是順便說一下工作;)

告訴我,如果您有其他問題

編輯:做了一些額外的分析,這是真的,真的很奇怪。 在crypo.bz如果​​該算法是正確的163爲OC

160是NC

但161是MC?

如果有人知道這一點,請告訴我!

EDITEDIT:

這裏是加密的,但不編碼字符串 '#ÔèïH§¢6pbpÊ]õªœIôŒ>Yœ5îfäGuæxÖa... E6°'

你的程序需要像半秒找到鑰匙;)

enter image description here

相關問題