Created
May 27, 2021 12:16
-
-
Save ignis-sec/4c8c7a18d483b4c637f96fb3414e71f5 to your computer and use it in GitHub Desktop.
McAffee's weird XOR stuff (https://twitter.com/officialmcafee/status/1397568860082122752)
This file contains hidden or 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
#https://twitter.com/officialmcafee/status/1397568860082122752 | |
#https://twitter.com/ahakcil/status/1397888724936105987 | |
import random | |
import copy | |
RST = '\033[0m' | |
def rand_data(size): | |
d = [] | |
for i in range(size): | |
d.append(random.randrange(0,255)) | |
return d | |
def dump_vars(original_set,d): | |
for i in range(len(d)): | |
for j in range(len(original_set)): | |
if(d[i]==original_set[j][i]): | |
print(f'\033[{91+j}m', end='') | |
print(f"{d[i]:3}", end='') | |
print(RST, end='') | |
if(i !=len(d)-1): | |
print(", ", end='') | |
else: | |
print("") | |
def dump_set(original_set, set): | |
for i in range(len(set)): | |
print(f"{chr(ord('A')+i)}=", end='') | |
dump_vars(original_set, set[i]) | |
def arr_xor(arr1,arr2): | |
ret = [] | |
for i in range(len(arr1)): | |
ret.append(arr1[i]^arr2[i]) | |
return ret | |
def seq_xor(set): | |
origin = copy.deepcopy(set) | |
for i in range(1,len(set)): | |
set[i] = arr_xor(set[i-1],set[i]) | |
set[0] = arr_xor(set[0],set[-1]) | |
def final_xor(set,original_set): | |
for i in range(1,len(set)): | |
set[i] = arr_xor(set[i-1], set[i]) | |
iter_counts = [4,3,2,1] | |
for i in range(3,7): | |
set = [] | |
original_set = [] | |
for k in range(i): | |
set.append(rand_data(5)) | |
original_set = copy.deepcopy(set) | |
print(f"{i} DATA SETS###########") | |
dump_set(original_set,set) | |
print() | |
for j in range(iter_counts[i-3]): | |
seq_xor(set) | |
print(f"Iteration {j+1}=====") | |
dump_set(original_set,set) | |
print("Final xor=====") | |
final_xor(set,original_set) | |
dump_set(original_set,set) | |
print() | |
#part below is for finding stable points | |
#exit() | |
def compare_sets(set1,set2): | |
for i in range(len(set1)): | |
for j in range(len(set1[0])): | |
if(set1[i-1][j]!=set2[i][j]): | |
return False | |
return True | |
for l in range(3,25): | |
print(f"{l} DATA SETS###########") | |
set = [] | |
original_set = [] | |
for k in range(l): | |
original_set.append(rand_data(5)) | |
set = copy.deepcopy(original_set) | |
#print("Starting with following:") | |
#dump_set(original_set,set) | |
#print() | |
found=0 | |
for j in range(2500000): | |
seq_xor(set) | |
set_save = copy.deepcopy(set) | |
final_xor(set_save,original_set) | |
if(compare_sets(set_save,original_set)): | |
print(f"Found in iteration {j+1}") | |
#dump_set(original_set,set_save) | |
found=1 | |
break | |
if not found: print("NOT FOUND.") | |
else: print("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment