Pages: [1]
Author Topic: BCB XOR key breaker (Python)  (Read 2458 times)
prj
Hero Member
*****

Karma: +1072/-481
Offline Offline

Posts: 6037


« on: August 26, 2022, 02:29:31 AM »

Code:
def stripBCBHead(imgxor):
return imgxor[imgxor.index(b"\x1A\x01") + 2:]

def freqtable(data, klen):
freqtable = {}
for x in range (0, klen):
curfreq = {}
for y in range (0, 256):
curfreq[y] = 0
freqtable[x] = curfreq

for nr in range(len(data)):
freqtable[nr % klen][data[nr]] += 1

return freqtable

def findXORkeyfreq(bcbdata, byte, confidence, maxlen):
data = stripBCBHead(bcbdata)
keyFound = False
key = bytearray()

for curlen in reversed(range(4, maxlen+1)):
fqtable = freqtable(data, curlen)
key = bytearray(curlen)

avgconf1 = 0
for fqpos in sorted(fqtable):
sortedlist = sorted(fqtable[fqpos].items(), key=lambda x: x[1], reverse=True)
avgconf1 += 100 - sortedlist[1][1]/sortedlist[0][1]*100
key[fqpos] = sortedlist[0][0] ^ byte

avgconf1 = avgconf1/curlen

if (avgconf1 >= confidence):
key = deleterepeat(key)
return key
return b""

Logged

PM's will not be answered, so don't even try.
Log your car properly - WinOLS database - Tools/patches
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Page created in 0.011 seconds with 16 queries. (Pretty URLs adds 0s, 0q)