Created
September 5, 2014 23:44
-
-
Save rolandshoemaker/028bb6af159963fcfbc7 to your computer and use it in GitHub Desktop.
Python function to find every possible permutation of a input hexademical key where one bit of one byte in the key is flipped, extremely quick and dirty...
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
def bitFlip(key): | |
flippedKeys = [] | |
for i in range(0, len(key), 2): | |
bits = bin(int(key[i:i+2], base=16)) | |
for j, b in enumerate(bits[2:len(bits)]): | |
flip = list(copy.deepcopy(bits[2:len(bits)])) | |
flip[j] = (1)^int(b) | |
#if j < len(flip)-1: | |
# flip[j+1] = (1)^int(b) | |
bitStr = "" | |
for f in flip: | |
bitStr += str(f) | |
flippedKey = copy.deepcopy(key) | |
if not flippedKey[0:i-2]+hex(int(bitStr, base=2))[2:4] in flippedKeys and not flippedKey[0:i-2]+hex(int(bitStr, base=2))[2:4]+flippedKey[i:len(flippedKey)] in flippedKeys: | |
if len(flippedKey[0:i-2]+hex(int(bitStr, base=2))[2:4]) == len(key): | |
flippedKeys.append(flippedKey[0:i-2]+hex(int(bitStr, base=2))[2:4])#+flippedKey[i+2:len(flippedKey)]) | |
elif len(flippedKey[0:i-2]+hex(int(bitStr, base=2))[2:4]+flippedKey[i:len(flippedKey)]) == len(key) : | |
flippedKeys.append(flippedKey[0:i-2]+hex(int(bitStr, base=2))[2:4]+flippedKey[i:len(flippedKey)]) | |
return flippedKeys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment