In: Computer Science
create a file with 1000 alphanumeric ones written one per line. Write a program in python that randomly selects 100 of them, holds the index of each alphanumeric, adds the hash of the previous 100 and tries to find a random alphanumeric so that if it adds it to the list of indicators the SHA256 of the whole to have 10 zeros at the end. You start with the original Hash: 1111..111
my solution so far:
import random
import string
# here i create a file with 1000 alphanumerics
f = open("key.txt", "w")
randomstring =
''.join(random.SystemRandom().choice(string.ascii_letters +
string.digits) for _ in range(1000))
for char in randomstring:
f.write(char)
f.write("\n")
f.close()
with open("key.txt") as m:
sample_of_100 = random.sample(m.readlines(),100)
print(sample_of_100)
idx = []
sample_str = ' '.join([str(elem) for elem in sample_of_100])
for num, name1 in enumerate(sample_str, start=1):
for num, name2 in enumerate(randomstring, start=1):
if name1 == name2:
idx = name2
print("index {}: {}" .format(randomstring.index(name1), idx))
import random import string import hashlib # here i create a file with 1000 alphanumerics f = open("key.txt", "w") randomstring = ''.join(random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(1000)) for char in randomstring: f.write(char) f.write("\n") f.close() with open("key.txt") as m: sample_of_100 = random.sample(m.readlines(),100) print(sample_of_100) idx = [] sample_str = ' '.join([str(elem) for elem in sample_of_100]) for num, name1 in enumerate(sample_str, start=1): for num, name2 in enumerate(randomstring, start=1): if name1 == name2: idx = name2 print("index {}: {}" .format(randomstring.index(name1), idx)) a = hashlib.sha256() a.update(name1.encode('utf-8')) print(a.digest())
""" function prints hash value of number which are equal"""