Python Iterate密码组合以查找字符串的键
我无法强制使用RC4/ARC4加密的字符串的密钥 这是加密字符串:Python Iterate密码组合以查找字符串的键,python,encryption,Python,Encryption,我无法强制使用RC4/ARC4加密的字符串的密钥 这是加密字符串: E7Ev08\u meojbybixhrktkqnrsc4hkriz7xpsy3p4xahupj41dlzu9 并且字符串也使用base64散列,因此完整的编码字符串为: rtdfdja4x01fb2pzqml4sfjlvetrbljtqzroa3jpwjdyuhn5m3a0eevvbqndfebhp1oq== #-*- coding: utf-8 -*- import threading import sys import t
E7Ev08\u meojbybixhrktkqnrsc4hkriz7xpsy3p4xahupj41dlzu9
并且字符串也使用base64散列,因此完整的编码字符串为:
rtdfdja4x01fb2pzqml4sfjlvetrbljtqzroa3jpwjdyuhn5m3a0eevvbqndfebhp1oq==
#-*- 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()
我用它来加密字符串并用UTF-8编码
问题:
为什么我的脚本找不到钥匙
(我没有收到任何错误消息,如果我的代码中遗漏了什么,或者问题的解决方法,这更像是一个一般性的问题。)
明文:
这是我加密的东西
,密钥:ABCFMSG
好吧,看来crypo.bz使用了一个非常奇怪的系统。基本上,它们有一个非常奇怪的编码,如果你仅仅使用它们的字符,就会导致差异
例如,使用键“a”对“a”进行编码应产生一个值为163的字符
十六进制A3。在crypo.bz中,我们得到的是“oc”
所以你有两种可能。要么做一些密文分析,要么使用另一个网站。我推荐这一个,因为他们会告诉你他们对结果的编码:
把十六进制数转换成字符串,你应该能够破译它
顺便说一下,您的代码似乎正在运行;)
如果您还有其他问题,请告诉我
编辑:做了一些额外的分析,这真的很奇怪。
在crypo.bz中,如果算法正确,则163为oc
160是nc
但是161是mc
如果有人知道了,请告诉我
编辑:
这里是加密但未编码的字符串“#ÔèH§、6pbpÊ]õIœIŒ>Yœ5îfäGuæxÖa…ë6°”
您的程序需要半秒钟才能找到密钥;)
缩进不一致可能会导致问题。如果提供正确的键,说明是否有效?还有80亿个可能的键,可能需要很长很长时间time@JeD但在这种情况下,关键是
ABCFMSG
。