From 942f81efe5e52f858d94e5afed4a5d3cdd58e8f7 Mon Sep 17 00:00:00 2001 From: Benjamin_Loison Date: Tue, 2 May 2023 17:45:47 +0200 Subject: [PATCH] Add `statisticsFromHashes.py` Signed-off-by: Benjamin_Loison --- statisticsFromHashes.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 statisticsFromHashes.py diff --git a/statisticsFromHashes.py b/statisticsFromHashes.py new file mode 100644 index 0000000..49e45c9 --- /dev/null +++ b/statisticsFromHashes.py @@ -0,0 +1,41 @@ +import os, matplotlib.pyplot as plt + +path = '/home/benjamin/Desktop/bens_folder/school/m2/internship/work/romaric/me/' + +os.chdir(path) + +def getBinaryHash(hexHash): + binaryHash = "{0:b}".format(int(hexHash, 16)) + binaryHash = (256 - len(binaryHash)) * '0' + binaryHash + return binaryHash + +def getNumberOfLeadingBinaryZerosOfHash(hexHash): + binaryHash = getBinaryHash(hexHash) + return len(binaryHash) - len(binaryHash.lstrip('0')) + +additionalZeros = {} + +with open('hashes.txt') as f: + lines = f.read().splitlines() + for line in lines: + lineParts = line.split() + hash = lineParts[0] + target = lineParts[1] + leadingBinaryZerosHash = getNumberOfLeadingBinaryZerosOfHash(hash) + leadingBinaryZerosTarget = getNumberOfLeadingBinaryZerosOfHash(target) + #print(leadingBinaryZerosHash, leadingBinaryZerosTarget) + additionalZero = leadingBinaryZerosHash - leadingBinaryZerosTarget + if additionalZero in additionalZeros: + additionalZeros[additionalZero] += 1 + else: + additionalZeros[additionalZero] = 1 + +X, Y = [], [] + +for i in range(max(additionalZeros) + 1): + if i in additionalZeros: + X += [i] + Y += [additionalZeros[i] / len(lines)] + +plt.plot(X, Y) +plt.show()