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

In Python: read in 'marks.txt' . The file format is one number per line. Your program...
In Python: read in 'marks.txt' . The file format is one number per line. Your program will run through all these numbers, and make sure that they are valid input. you have to Create two lists: one for valid numbers and one for invalid numbers. For a number to be valid the number has to: Must be less than or equal to 100 Must be greater than or equal to 0 Must not have any letters inside of it (it...
In Python please:  Number the Lines in a File: Create a program that adds line numbers to...
In Python please:  Number the Lines in a File: Create a program that adds line numbers to a file. The name of the input file will be read from the user, as will the name of the new file that your program will create. Each line in the output file should begin with the line number, followed by a colon and a space, followed by the line from the input file.
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:...
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).
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT