optimizing a bit pyDes module used in Oracle hash cracking

This commit is contained in:
Miroslav Stampar 2011-12-26 15:33:49 +00:00
parent 08071f42d0
commit 068ff92dc4
3 changed files with 719 additions and 716 deletions

View File

@ -1,8 +1,5 @@
#!/usr/bin/env python
#Copyright (c) 2010, Miroslav Stampar <miroslav.stampar@gmail.com>
#Added formatXML method
#Copyright (c) 2010, Chris Hall <chris.hall@mod10.net>
#All rights reserved.

View File

@ -419,32 +419,37 @@ class des(_baseDes):
# Turn the strings into integers. Python 3 uses a bytes
# class, which already has this behaviour.
data = [ord(c) for c in data]
l = len(data) * 8
result = [0] * l
result = [False] * len(data) * 8
pos = 0
for ch in data:
i = 7
while i >= 0:
if ch & (1 << i) != 0:
result[pos] = 1
else:
result[pos] = 0
pos += 1
i -= 1
result[pos + 0] = (ch & (1 << 7) != 0)
result[pos + 1] = (ch & (1 << 6) != 0)
result[pos + 2] = (ch & (1 << 5) != 0)
result[pos + 3] = (ch & (1 << 4) != 0)
result[pos + 4] = (ch & (1 << 3) != 0)
result[pos + 5] = (ch & (1 << 2) != 0)
result[pos + 6] = (ch & (1 << 1) != 0)
result[pos + 7] = (ch & (1 << 0) != 0)
pos += 8
return result
def __BitList_to_String(self, data):
"""Turn the list of bits -> data, into a string"""
result = []
result = [0] * (len(data) >> 3)
pos = 0
c = 0
while pos < len(data):
c += data[pos] << (7 - (pos % 8))
if (pos % 8) == 7:
result.append(c)
c = 0
pos += 1
c = data[pos + 0] << (7 - 0)
c += data[pos + 1] << (7 - 1)
c += data[pos + 2] << (7 - 2)
c += data[pos + 3] << (7 - 3)
c += data[pos + 4] << (7 - 4)
c += data[pos + 5] << (7 - 5)
c += data[pos + 6] << (7 - 6)
c += data[pos + 7] << (7 - 7)
result[pos >> 3] = c
pos += 8
if _pythonMajorVersion < 3:
return ''.join([ chr(c) for c in result ])
@ -453,7 +458,8 @@ class des(_baseDes):
def __permutate(self, table, block):
"""Permutate this block with the specified table"""
return list(map(lambda x: block[x], table))
#return map(lambda x: block[x], table)
return list(block[x] for x in table)
# Transform the secret key, so that it is ready for data processing
# Create the 16 subkeys, K[1] - K[16]
@ -506,7 +512,7 @@ class des(_baseDes):
self.R = self.__permutate(des.__expansion_table, self.R)
# Exclusive or R[i - 1] with K[i], create B[1] to B[8] whilst here
self.R = list(map(lambda x, y: x ^ y, self.R, self.Kn[iteration]))
self.R = map(lambda x, y: x ^ y, self.R, self.Kn[iteration])
B = [self.R[:6], self.R[6:12], self.R[12:18], self.R[18:24], self.R[24:30], self.R[30:36], self.R[36:42], self.R[42:]]
# Optimization: Replaced below commented code with above
#j = 0
@ -542,7 +548,7 @@ class des(_baseDes):
self.R = self.__permutate(des.__p, Bn)
# Xor with L[i - 1]
self.R = list(map(lambda x, y: x ^ y, self.R, self.L))
self.R = map(lambda x, y: x ^ y, self.R, self.L)
# Optimization: This now replaces the below commented code
#j = 0
#while j < len(self.R):
@ -603,7 +609,7 @@ class des(_baseDes):
# Xor with IV if using CBC mode
if self.getMode() == CBC:
if crypt_type == des.ENCRYPT:
block = list(map(lambda x, y: x ^ y, block, iv))
block = map(lambda x, y: x ^ y, block, iv)
#j = 0
#while j < len(block):
# block[j] = block[j] ^ iv[j]
@ -612,7 +618,7 @@ class des(_baseDes):
processed_block = self.__des_crypt(block, crypt_type)
if crypt_type == des.DECRYPT:
processed_block = list(map(lambda x, y: x ^ y, processed_block, iv))
processed_block = map(lambda x, y: x ^ y, processed_block, iv)
#j = 0
#while j < len(processed_block):
# processed_block[j] = processed_block[j] ^ iv[j]

View File

@ -188,7 +188,7 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio
kb.threadContinue = True
kb.threadException = False
if conf.get('hashDB', None):
if conf.get("hashDB", None):
conf.hashDB.flush(True)
if cleanupFunction: