Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q1. Create a simple blockchain system for playing a tic-tac-toe game between two parties, Alice and Bob. Both players have an initial block to start

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Q1. Create a simple blockchain system for playing a tic-tac-toe game between two parties, Alice and Bob. Both players have an initial block to start their play. Let Alice always start first for simplicity. The initial block, Block0.json, for both Alice and Bob is set as follow: { "TxID": 0, "Hash": "This is the genesis block.", "Nonce": 0, "Transaction": } Figure 1. Blocko.json At each turn, a player (e.g., Alice) who takes the turn creates a new block in JSON format and send it to the other player (e.g., Bob) who plays tic-tac-toe together. Each block is formed as follows: { "TxID": , "Hash": "", "Nonce": , "Transaction": } The entities in the above block are computed in a way described as follows: 1. is an incremental counter, which increased by 1 on each turn. of a new block = of the last block +1 2. "Hash" is the output of the SHA256 hash with the last block and Nonce". The player increases the value of Nonce" from 0 by 1 until the value of the hash output is less than 2248 = SHA256(/) and to a set of bytes so that they can be taken as inputs of SHA256. You can convert them using String encodemethod. After the conversion, you can append to . (e.g., str(i).encode where i is and set as integer.) 3. "Transaction" is the choice of the player in its turn. It contains the player name and its choice of the space on the tic-tac-toe board (e.g. ["Alice",5]). To make your code simple, assume that Alice and Bob take a random empty space in their turn. For example, Assume that we use the following grid to play a tic-tac-toe game. 1 2 3 4 5 6 7 8 9 The first block (block1.json) is generated by Alice as follows. { "TxID": 1, "Hash":"00e 260d79735cd52f38358289f890019e376117be1866 027e172c391383ff5b8", "Nonce":11, "Transaction": ["Alice",5] } Note that in your program, Alice must choose a space, randomly. Then, Alice saves the block in her storage and sends it to Bob. Once Bob receives the block, Bob validates the received block and save it to its storage. Then, Bob creates a following block and send it to Alice: { "TxID":2, "Hash":"0053560513000535db6692c972aab41ec30ec9ec3b43a5 bobof1c8eafce 20c3f", "Nonce": 742, "Transaction": ["Bob",1] } Note that in your program, Bob must randomly choose a space among the spaces not taken previously. The game will continue until all spaces in the board are taken. Alice and Bob keep each block in a separate file (block0.json, block1.json, ..., block9.json) in their local storage. Before each player executes their turn, it must check that the block received is valid. Make the players exchange blocks online. You can use the PubNub package to implement this in Python. Marks Block generation process implementation. (30 marks) Block validation process implementation. (10 marks) The other basic requirements of the system (e.g., implementation of a tic- tac-toe game and handling JSON format.) (30 marks) Implementation of blocks exchange protocol (20 marks) Report (10 marks) Submission Make a folder named Assignment3 and include Programs for Alice and Bob. The history of one of the completed games (e.g., blocko.txt, blocki.txt, ..., and block 9.txt) Report explaining the requirements to execute your program and the expected outcome of your program. "TXID": 0, "Hash": "This is the genesis block." "Nonce": 0, "Transaction": [] Q1. Create a simple blockchain system for playing a tic-tac-toe game between two parties, Alice and Bob. Both players have an initial block to start their play. Let Alice always start first for simplicity. The initial block, Block0.json, for both Alice and Bob is set as follow: { "TxID": 0, "Hash": "This is the genesis block.", "Nonce": 0, "Transaction": } Figure 1. Blocko.json At each turn, a player (e.g., Alice) who takes the turn creates a new block in JSON format and send it to the other player (e.g., Bob) who plays tic-tac-toe together. Each block is formed as follows: { "TxID": , "Hash": "", "Nonce": , "Transaction": } The entities in the above block are computed in a way described as follows: 1. is an incremental counter, which increased by 1 on each turn. of a new block = of the last block +1 2. "Hash" is the output of the SHA256 hash with the last block and Nonce". The player increases the value of Nonce" from 0 by 1 until the value of the hash output is less than 2248 = SHA256(/) and to a set of bytes so that they can be taken as inputs of SHA256. You can convert them using String encodemethod. After the conversion, you can append to . (e.g., str(i).encode where i is and set as integer.) 3. "Transaction" is the choice of the player in its turn. It contains the player name and its choice of the space on the tic-tac-toe board (e.g. ["Alice",5]). To make your code simple, assume that Alice and Bob take a random empty space in their turn. For example, Assume that we use the following grid to play a tic-tac-toe game. 1 2 3 4 5 6 7 8 9 The first block (block1.json) is generated by Alice as follows. { "TxID": 1, "Hash":"00e 260d79735cd52f38358289f890019e376117be1866 027e172c391383ff5b8", "Nonce":11, "Transaction": ["Alice",5] } Note that in your program, Alice must choose a space, randomly. Then, Alice saves the block in her storage and sends it to Bob. Once Bob receives the block, Bob validates the received block and save it to its storage. Then, Bob creates a following block and send it to Alice: { "TxID":2, "Hash":"0053560513000535db6692c972aab41ec30ec9ec3b43a5 bobof1c8eafce 20c3f", "Nonce": 742, "Transaction": ["Bob",1] } Note that in your program, Bob must randomly choose a space among the spaces not taken previously. The game will continue until all spaces in the board are taken. Alice and Bob keep each block in a separate file (block0.json, block1.json, ..., block9.json) in their local storage. Before each player executes their turn, it must check that the block received is valid. Make the players exchange blocks online. You can use the PubNub package to implement this in Python. Marks Block generation process implementation. (30 marks) Block validation process implementation. (10 marks) The other basic requirements of the system (e.g., implementation of a tic- tac-toe game and handling JSON format.) (30 marks) Implementation of blocks exchange protocol (20 marks) Report (10 marks) Submission Make a folder named Assignment3 and include Programs for Alice and Bob. The history of one of the completed games (e.g., blocko.txt, blocki.txt, ..., and block 9.txt) Report explaining the requirements to execute your program and the expected outcome of your program. "TXID": 0, "Hash": "This is the genesis block." "Nonce": 0, "Transaction": []

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management System MCQs Multiple Choice Questions And Answers

Authors: Arshad Iqbal

1st Edition

1073328554, 978-1073328550

More Books

Students also viewed these Databases questions

Question

d. Who are important leaders and heroes of the group?

Answered: 1 week ago

Question

When is it appropriate to use a root cause analysis

Answered: 1 week ago

Question

6. Conduct a cost-benefit analysis for a training program.

Answered: 1 week ago