Last active
March 31, 2016 12:22
-
-
Save neugen86/8d7d89c3970906836e51c43aeb18ba71 to your computer and use it in GitHub Desktop.
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 random | |
a = 77 | |
b = 88 | |
print "a = ", a | |
print "b = ", b | |
array = [] | |
for i in range(1, 5): | |
for j in range(2): | |
array.append(512 * i) | |
array.append(a) | |
array.append(b) | |
random.shuffle(array) | |
print "array = ", array | |
a = 0 | |
b = 0 | |
xor = 0 | |
bit_xors = [] | |
for i in range(32): | |
bit_xors.append(xor) | |
def isBitSet(value, bit): | |
return value & (1 << bit) != 0 | |
for i in range(0, len(array)): | |
element = array[i] | |
xor = xor ^ element | |
for j in range(len(bit_xors)): | |
if isBitSet(element, j): | |
bit_xors[j] = bit_xors[j] ^ element | |
print "xor = ", bin(xor) | |
print bit_xors | |
a_found = False | |
b_found = False | |
for i in range(len(bit_xors)): | |
element = bit_xors[i] | |
if (element != 0) and (element != xor): | |
if not a_found and b_found: | |
a_found = True | |
a = element | |
else: | |
b_found = True; | |
b = element | |
print "a = ", a, " (", bin(a), ")" | |
print "b = ", b, " (", bin(b), ")" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment