Skip to content

Instantly share code, notes, and snippets.

@ryanamaral
Forked from ignis-sec/mcaffee.py
Last active December 8, 2022 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanamaral/4a149e7fe214de7b1114c234d4fc5fba to your computer and use it in GitHub Desktop.
Save ryanamaral/4a149e7fe214de7b1114c234d4fc5fba to your computer and use it in GitHub Desktop.

Boolean algebra is one of the foundations of computer science.

There is an unusual property of the boolean XOR operation that I doubt many, or anyone at all, has considered:

If you take any three sets of characters of any equal length - let's label them A, B and C - and then:

XOR A to B Then XOR the result of B to C Then similarly XOR C to A

And then perform 4 iterations of the above.

And finally:

XOR A to B And then B to C

It will result in the original contents of A moved to C, C moved to B and B moved to A.

Of interest here is that the 3 results of the 3rd iteration, though deterministic as a whole, are entirely random within each of the 3 independent data segments. Thus if any one of the 3 segments is missing or withheld, it is impossible, from the remaining 2 to extract even the tiniest fragment of the 3 original contents.

The simplicity of this process is astonishing. A person of average intelligence could decode a message, using pencil and paper, providing they possessed all three interim segments.

I'm describing this tidbit in the hopes that my observations might be of some small use to those engaged in the research of cryptography.

Addendum:

The same concept of sequential XOR operations works with 4 data sets requiring 3 iterations and 5 data sets with 2 iterations.

Strangely with 6 sets, the process unravels and produces chaos no matter how many iterations.

Please God, someone explain.

(source)

#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("")
@ryanamaral
Copy link
Author

McAffee's point:

Of interest here is that the 3 results of the 3rd iteration, though deterministic as a whole, are entirely random within each of the 3 independent data segments. Thus if any one of the 3 segments is missing or withheld, it is impossible, from the remaining 2 to extract even the tiniest fragment of the 3 original contents.

ChatGPT:

While it is true that the results of the XOR operations in your described process are deterministic and will always produce the same result given the same input, it is not accurate to say that the results are "entirely random" or that it is impossible to extract any information from the remaining two segments if one is missing.

The XOR operation is a binary operation that takes two input values and produces an output value. The output value is determined by comparing the input values bit by bit and setting the corresponding output bit to 1 if the input bits are different, and 0 if they are the same. Because of this, the output value of an XOR operation will always be completely determined by the input values.

In your described process, the XOR operation is being performed on sets of characters, which are sequences of bits. The output of the XOR operation will be a new set of characters with the same length as the input sets. The resulting characters will be determined by the input characters in a deterministic way, as described above.

However, it is not accurate to say that the resulting characters are "entirely random". The output characters will be determined by the input characters, and it is possible to extract some information about the input characters from the output characters, even if one of the input sets is missing.

For example, suppose we have three sets of characters A, B, and C, and we perform the XOR operations as described in your question. The resulting sets of characters D, E, and F will be determined by the input sets in a deterministic way, but it is still possible to learn some information about the input sets by examining the output sets. For example, if we know the values of two of the output sets (D and E, for instance), we can use the XOR operation to recover the value of the third output set (in this case, F).

In summary, while the swap property of XOR is an interesting mathematical property, it is not accurate to say that the resulting sets of characters are "entirely random" or that it is impossible to extract any information from the remaining sets if one is missing. The output sets will be determined by the input sets in a deterministic way, and it is possible to learn some information about the input sets by examining the output sets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment