虚假键过滤器

时间:2014-04-22 15:37:56

标签: python algorithm encryption cryptography pycrypto

是否有任何可能的方法来过滤加密系统中的密钥空间以获取一组密钥来解密出有效的文本(具有相同语言或可读的文本)?

我尝试了一种随机方法,并获得了一定数量的密钥,但实际上并不需要文本大小

from Crypto.Cipher import ARC4
import base64, string, time, random
key = ''.join(random.choice(string.ascii_letters + string.digits ) for i in       range(8))
obj1 = ARC4.new(key)
obj2 = ARC4.new(key)
text = 'abcdefgh'
cipher_text = base64.b64encode(obj1.encrypt(text))

decoded_text= obj2.decrypt(base64.b64decode(cipher_text))

Dict={}
count=0
valid = set(string.ascii_letters + string.digits )
def test(s):
    return set(s).issubset(valid)

print; print 'plain text: ', text
print; print 'Actual key: ', key 
print; print 'Cipher text: ', cipher_text

timeout=time.time()+60
while time.time()< timeout:
   count+=1
   key = ''.join(random.choice(string.ascii_letters + string.digits ) for i in range(8))
   obj2 = ARC4.new(key)
   decoded= obj2.decrypt(base64.b64decode(cipher_text))
   if test(decoded):
       Dict.update({'key: '+key : 'Valid Decrypted Text: '+decoded})
import pprint
print; print 'Analysis: '
pprint.pprint(Dict)
print;print 'Number of valid Decrypted Text: ', len(Dict)
print;print 'Total number of decryption performed: ', count

输出:

plain text:  abcdefgh

Actual key:  go6oMkCG

Cipher text:  JB1a3osG+es=

Analysis: 
{'key: 0UUvjzLw': 'Valid Decrypted Text: mzptBVo4',

 'key: 2beOXKN1': 'Valid Decrypted Text: Yhz3jIL8',

 'key: 3Eq7MKwu': 'Valid Decrypted Text: GA9BTdzy',

 'key: 3jUQPXs8': 'Valid Decrypted Text: 3gCa3KBG',

.

.

Number of valid Decrypted Text:  36

Total number of decryption performed:  2275140

有没有更好的解决这些键。 此类密钥可能通过引入混淆来强化加密技术

0 个答案:

没有答案