summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2021-08-27 22:34:19 -0400
committerMalfurious <m@lfurio.us>2021-08-27 22:34:19 -0400
commit1522a21d24add0d78f7e4a5fae7654b709045754 (patch)
treeb5fb4bd061ecb4aac83feaa6fb0a484b0fe03bb7
parent0f63e3ddae28e2f150f66493a2dbe84f0a897f86 (diff)
downloadSorensenCompression-1522a21d24add0d78f7e4a5fae7654b709045754.tar.gz
SorensenCompression-1522a21d24add0d78f7e4a5fae7654b709045754.zip
Forward-port Python POC to Python 3
Signed-off-by: Malfurious <m@lfurio.us>
-rwxr-xr-x[-rw-r--r--]GarbageProofOfConcept.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/GarbageProofOfConcept.py b/GarbageProofOfConcept.py
index 0c07873..e6e4030 100644..100755
--- a/GarbageProofOfConcept.py
+++ b/GarbageProofOfConcept.py
@@ -1,7 +1,9 @@
+#!/usr/bin/env python
+
import hashlib
from itertools import combinations
-data = "abc"
+data = b"abc"
length = len(data)
hexdigest = hashlib.sha256(data).hexdigest()
@@ -21,24 +23,24 @@ lookupTable = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3,
6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8]
sum1 = 0
-for i in xrange(length):
+for i in range(length):
sum1 += lookupTable[bytearray(data)[i]]
-print("The length is: {0}").format(length)
-print("The ones count is: {0}").format(sum1)
+print("The length is: {0}".format(length))
+print("The ones count is: {0}".format(sum1))
combinations = list(combinations(range(length * 8),sum1))
numCombs = len(combinations)
count = 1
for comb in combinations:
- print("Trying {0}/{1}").format(count, numCombs)
+ print("Trying {0}/{1}".format(count, numCombs))
count += 1
a = [0] * length
for bit in comb:
- a[bit/8] |= 1 << (bit % 8)
+ a[bit//8] |= 1 << (bit % 8)
if hashlib.sha256(bytearray(a)).hexdigest() == hexdigest:
- print("Found! {0}").format(a)
+ print("Found! {0}".format(a))
break
else:
print("failed to find")