Question

In: Computer Science

create a file with 1000 alphanumeric ones written one per line. Write a program in python...

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))

Solutions

Expert Solution

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"""


Related Solutions

Write a Python program that reads a file, input by the user, containing one word/token per...
Write a Python program that reads a file, input by the user, containing one word/token per line with an empty line between sentences. The program prints out the longest word found in the file along with its length.
(PYTHON) Write a program that does the following: reads each line from a txt file and...
(PYTHON) Write a program that does the following: reads each line from a txt file and convert it to lowercase counts the number of instances of: the characters 'a', 'e','i','o' and 'u' in the file creates a new file of file type .vowel_profile print outs lines in the file indicating the frequencies of each of these vowels Example input/output files: paragraph_from_wikipedia.txt (sample input) link: https://cs.nyu.edu/courses/fall19/CSCI-UA.0002-007/paragraph_from_wikipedia.txt paragraph_from_wikipedia.vowel_profile (sample output) link: https://cs.nyu.edu/courses/fall19/CSCI-UA.0002-007/paragraph_from_wikipedia.vowel_profile Please help!
Python Create a Python script file called hw3.py. Ex. 1. Write a program that inputs numbers...
Python Create a Python script file called hw3.py. Ex. 1. Write a program that inputs numbers from the user until they enter a 0 and computes the product of all these numbers and outputs it. Hint: use the example from the slides where we compute the sum of a list of numbers, but initialize the variable holding the product to 1 instead of 0. print("Enter n") n = int(input()) min = n while n != 0: if n < min:...
Python: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
Write a python program: There is a file called file 2. File2 is a txt file...
Write a python program: There is a file called file 2. File2 is a txt file and I have written the contents of file 2 below in the exact format it was in notepad. # This comment does not make sense # It is just to make it harder # The job description starts after this comment, notice that it has 4 lines. # This job description has 700150 hay system points\\ the incumbent will administer the spending of kindergarden...
Write a program to convert a text-file containing expressions (one per line) into post-fix expressions outputted...
Write a program to convert a text-file containing expressions (one per line) into post-fix expressions outputted to a file of your choice using a stack with one space between operators and variables (one letter variables) and/or constants (one digit constants). IN PYTHON please
Write a program to convert a text-file containing expressions (one per line) into post-fix expressions outputted...
Write a program to convert a text-file containing expressions (one per line) into post-fix expressions outputted to a file of your choice using a stack with one space between operators and variables ( one letter variables) and/or constants (one digit constants).
Create a Python program that: Reads the content of a file (Vehlist.txt) The file contains matching...
Create a Python program that: Reads the content of a file (Vehlist.txt) The file contains matching pairs of vehicle models and their respective makes Separate out the individual make and model on each line of the file Add the vehicle make to one list, and the vehicle model to another list; such that they are in the same relative position in each list Prompt the user to enter a vehicle model Search the list containing the vehicle models for a...
Create a Python program file and . Your program will draw random circles with filled and...
Create a Python program file and . Your program will draw random circles with filled and non-filled color (random colors) and rectangles, fill andnon-fill color (also random colors) on the canvas. At least 10 for each category
Write a program that will read in from input file one line at a time until...
Write a program that will read in from input file one line at a time until end of file and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by either whitespace, a period, a comma or the beginning or end of the line. You can assume that the input consists entirely of letters, whitespaces, commas and periods....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT