Created
April 3, 2018 17:07
-
-
Save AxDSan/d741935628756cb1aa955c65f9ba269e to your computer and use it in GitHub Desktop.
A Rust CrackMe Password Checksum Generator and a failed BruteForcer (it just takes too much time XD)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import binascii | |
import itertools | |
import sys | |
def add_hex(A, B): | |
A = "0"+A | |
B = "0"+B | |
#Remember all pattern include carry in variable d. | |
i2h = dict(zip(range(16), "0123456789abcdef")) | |
a = [(i,j) for i in "0123456789abcdef" for j in "0123456789abcdef"] | |
b = list(map(lambda t: int(t[0],16)+int(t[1],16), a)) | |
c = ["0"+i2h[i] if i<16 else "1"+i2h[i-16] for i in b]#list of digit include carry | |
d = dict(zip(a,c))#d={(digit,digit):digit,,,} | |
#Calculate with variable d. | |
result = "" | |
cur = "0" | |
nex = "0" | |
for i in itertools.zip_longest(A[::-1], B[::-1], fillvalue = "0"): | |
cur = d[(nex, d[i][1])][1] #cur = carry + digit + digit | |
if d[i][0]=='1' or d[(nex, d[i][1])][0]=='1':#nex = carry = carry + digit + digit | |
nex = "1" | |
else: | |
nex = "0" | |
result += cur | |
return result[::-1] | |
def getChecksum(s): | |
a = binascii.hexlify(bytes(s, encoding="utf8")) | |
r = 0 | |
for i in range(0, len(a), 2): | |
n = str(a[i:i+2].decode('utf-8')) | |
r = add_hex(n, str(r)) | |
return r.strip('0') | |
def BruteForce(): | |
chars = "0123456789abcdefghijklmnopqrstuvwxyz" | |
n = 3 | |
with open('bruteforce_log.txt', 'w') as fh: | |
for i in range(1, n + 1): | |
for item in itertools.product(chars, repeat=i): | |
s = "".join(item) | |
# print('checksum of: [','%s' % s, ']', 'is ', '%s' % getChecksum(s)) | |
fh.write(f'checksum for: [{s}] is [{getChecksum(s)}]\n') | |
fh.close() | |
BruteForce() | |
print('DONE!') | |
#print('0x{:X}'.format(int(getChecksum(str(sys.argv[1])), 16))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment