Python代写 | C&O 487/687: Assignment #5

本次Python作业是完成消息加密解密相关的程序

C&O 487/687: Assignment #5

1. [8 marks] PKI and message signing in Python
In order to stop the persistent problem of TA impersonation, dstebila has decided that all messages
from TAs to students should be cryptographically signed. Each TA will have their own public key
and dstebila will issue a certificate for each TA. When a TA sends a message to a student, they
also send along a signature on that message and a certificate for their public key and identity.
In q1.zip, you’ll find most of the code for this scheme. These scripts again use the Python
cryptography library that we previously used for question 1 of assignment 3. (Follow the instructions
from A3Q1 in order to get Python up and running for this question.) In particular, we have the
following scripts (you do not need to run or modify these scripts; we provide them so you can see
how we generated the data files for this problem):
• key gen.py is used to generate keys. After specifying an identity as an argument, it generates
a verification (public) key and a signing (secret) key and puts them in name.vk and name.sk.
So if you wanted to generate keys for Alice, you could run
python3 key gen.py alice
• sign.py is used to sign messages. The identity of the signer needs to be identified as an
argument, and the corresponding .sk file should be in the same directory as the script. Then
the script signs the contents of stdin and returns the signature to stdout, so it can be run as
python3 sign.py alice < message.txt > signature.txt
• generate certificate.py is used to create certificates. It takes in two parameters: (i) the
identity of the certificate issuer, and (ii) the identity of the certificate owner. The .sk file for
the certificate issuer must be present, as well as the .vk file for the certificate owner. So if
Alice wants to issue a certificate for Bob, it can be run as
python3 generate certificate.py alice bob > bob.cert
(a) [3 marks] Finish writing verify.py. Follow all the necessary checks to see if a message came
from an authorized source. Once you’re ready to test it, you can run
python3 verify.py dstebila ta name
Submit the source code for your script to Crowdmark.
(b) [5 marks] Now you’ll need to put your script into action. dstebila has distributed his verification key to you, which can be found in dstebila.vk. You can find messages you’ve received
from the TAs in the folders ajena, eeaton, phodges, swinnick, and vgilchrist. Which
messages can you verify as having actually come from the TA in question? If a message fails
the verification process, what caused it to fail?
2. [7 marks] Bitcoin transaction hash trees
In lectures, we saw that a Bitcoin block contained a list of the transactions in that block, and a
hash of all of the transactions. In this question, we will explore in a bit more detail how Bitcoin
actually implements this.
Instead of hashing the entire list of transactions, Bitcoin hashes transactions in a binary treelike structure. Suppose we have 2n transactions in a block. In order to generate the “hash of
transactions” to go into the block, first hash each individual transaction, then repeat the following
steps:
1. Pair up all the transaction hashes.
2. Hash each pair of transaction hashes.
3. Repeat, considering the new hash as a single transaction hash.
When there is only one hash left, it is called the root hash. The root hash is inserted into the block.
The figure below shows a hash tree for 8 transactions TA, TB, . . . , TH and root hash HABCDEF GH.
(a) [2 marks] Consider the 8-transaction tree below, constructed as described above, for the block
B.


程序代写代做C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB


本网站支持淘宝 支付宝 微信支付  paypal等等交易。如果不放心可以用淘宝交易!

E-mail: [email protected]  微信:itcsdx


如果您使用手机请先保存二维码,微信识别。如果用电脑,直接掏出手机果断扫描。

blank

发表评论