Saturday, October 22, 2016

script to find a single byte xored hex string

you can use the script from link below to generate xored hex string
http://www.atechnote.com/2016/10/xor-text-with-single-byte.html


1- the script is below

import enchant
from enchant import checker
import sys

rd = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736"
def xorSingleByte(chiperword):
    sentdic = {}
    rd = chiperword
    for i in range(256):
        sentdic[i]=[]
    for i in range(0,len(rd),2):
        dpart = rd[i:i+2]
        dint = int(dpart, 16)
       
        for i in range(256):
            xorout = int(bin(dint ^ i),2)
            sentdic[i].append(xorout)

    chk = checker.SpellChecker("en_US")
    resdict = {}
    for i in sentdic:
        s = ''
        score = 0
        resdict[chr(i)] ={}
        for j in sentdic[i]:
            s += chr(j)
       
        sl = s.split()
        for word in sl:
            try:
                wc = chk.check(word)
                if wc == True:
                    score += 1
            except:
                pass
        resdict[chr(i)]['word'] = s
        resdict[chr(i)]['score'] = score
    return resdict
   

rd = sys.argv[1]
#rd = "1c110611541506115400031b541d19041b0600151a0054041b1d1a000754001b5406111911191611065415161b010054101d17001d1b1a15060d541f110d0754"
resdict = xorSingleByte(rd)
for i in resdict:
    if resdict[i]['score'] > 3:
        print i, str(resdict[i]['score'])
        print str(resdict[i]['word'])




2- usage, unxor-hexstring.py hexstring
$ python unxor-hexstring.py c312631743526317420233b743d39243b2620353a2074243b3d3a202774203b7426313931393631267435363b212074303d37203d3b3a35262d743f312d2774 2> /dev/null
T 10
here are two important points to remember about dictionary keys

No comments:

Post a Comment