Add statisticsFromHashes.py
Signed-off-by: Benjamin_Loison <benjamin_loison@noreply.localhost>
This commit is contained in:
41
statisticsFromHashes.py
Normal file
41
statisticsFromHashes.py
Normal file
@@ -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()
|
||||
Reference in New Issue
Block a user