Part 1
· Hash Mining. Name the file hash_mining.py.
Write a program that accepts an input string, and outputs a SHA256 hash with a predefined pattern for that input string. You will define your own format for the hashes (see below).
Here is a sample execution of a program looking for hashes that start with “0000” using the input “Joe Snuffy”
· HASH MINER
· by me
·
· Input Text: Joe Snuffy
· Hash Found: 00000cf0a4c5c566bc1cf869f14974e97b0350063e640c6fb7b4531715d7c2a7
· Nonce: 19334
Watch the first 5 mins of the following video for a description of process of hash mining:
Play Video
We shall call the process of finding a particular hash “Hash Mining,” and it works as follows (pseudo code):
1. Ask user for input string s
2. Set the variable nonce to 1
3. Let C be the result of concatenating s and nonce as a string
4. Let H be the hash corresponding to C
5. While H has NOT the right format Do
6….Add one to nonce
7….Set C to the result of concatenating s and nonce
8….Let H the hash corresponding to C
9. End While
10. Display hash H
11. Display nonce value
Notes:
– Steps 7 and 8, are the same as 3 and 4.
– To obtain H in step 4 use: H = get_hash(C) . This function is provided below.
– In order to concatenate nonce at the end of s, you need to convert nonce to a string.
– In order to decide the condition in step 5 see below.
Hash Format
In the example above, the format of the hash is that it starts with ‘0000’
For this assignment, you will choose your own prefix pattern by using a word with at least 4 characters, and spelled only using the letters a thru f. You can find a list here: http://www.alecjacobson.com/weblog/?p=475
Theget_hash Function
In order to get the SHA256 hash of a string, add to your program the code below:
importhashlib
defget_hash(string):
m = hashlib.sha256()
m.update(str.encode(string))
returnm.hexdigest()
Mine A Hash For Your Name
Run the program using your full name as input. Copy the output hash at then end of your program as a comment. (10 out of 50 points)
How Do I Know It Actually Worked?
First, make sure the output hash has the format you selected.
Then, copy and paste the code above (the import statement and the get_hash function) in the shell. Last, call the function with your full name and the nonce together. For example, using the input “Angel Rivera” and the nonce 19334 we get:
>>>get_hash(“Joe Snuffy19334“)
00000cf0a4c5c566bc1cf869f14974e97b0350063e640c6fb7b4531715d7c2a7
Part 2
· List Maintainer. Name program list_maintainer.py
Write a program that allows the user to add, delete and organize the items in a list.
Your program will provide the following options:
o Append: adds an items, input by the user, at the end of the list.
o Delete: removes an item indicated by the user from the list.
o Move up: moves an item indicated by the user, to the previous position in the list.
o Move Down: moves an item indicated by the user to the next position in the list.
o Move Top: moves an item indicated by the user to the first spot in the list.
o Move Bottom: moves an item indicated by the user to the last position in the list.
o Swap: swaps two items indicated by the user in the list.
o List all: display the items in the list; one item per line.
o Quit: allows the user to end the program.
Your program shall show appropriate error messages when trying to move, swap, or delete items not found in the list.
You program shall also properly handle invalid actions, like trying to move up the first item in the list, or trying to move down the last item in the list.
In order to get you started, download the file list_maintainer_base.py which you can find at the bottom of this page.
Here is a sample run. Let’s assume we already added the following items (in this order): cake, cookies, ice cream.
Adding “donuts”