Question
if anyone sees the answer to this question please change it a bit This is python could you answer this as soon as possible? a)Create
if anyone sees the answer to this question please change it a bit
This is python
could you answer this as soon as possible?
a)Create a RSA public/private key pair with 1024 bits key length. The created RSA public {n,e} and private keys {n,d} need to be displayed in the following format:
b)Find a nonce which produces a hash value with hash algorithm SHA-256 satisfying requirement of the 8 least significant bits (LSB) being zero.
this is the hint
You should try many random integers as nonce (with a loop) until you successfully find a nonce that meets the requirement. The only output from this task is the nonce, which needs to be displayed with the following format (suppose the found nonce is 12345):
you may need this to help
here is all the information I have about this
1.1 Bitcoin Mining Bitcoin is a cryptocurrency. In the Bitcoin system Bitcoins are mined through proof-of-work mechanism. Bitcoin miners are given technical puzzles to solve. There is only one puzzle at any time with a given difficulty level, which is set by the system administrator. New puzzles are created after the current one is solved. The first miner who solves the puzzle is awarded a specified number of bitcoins. The winner creates and sign a new block with digital signature technology and broadcast to other Bitcoin users. The signed block is linked to the previous signed blocks. These blocks form a chain of blocks (called blockchain) as shown in the following figure. The new signed blocks are verified by others and could become mature after being confirmed by a given number of miners, which is measured by length of blocks linked to the new blocks.
1.2 Technical puzzle The puzzle set in the proof-of-work is to find a specific integer number (called nonce), which together with a few other numbers (such as hash value of the previous block, the transactions to be included to the new block) are hashed with SHA-256 algorithm and the hashed value satisfies a given condition. The puzzle can be formulated as follows: where preHash is the hash value of the previous block, Tx is transaction of bitcoins. levelHard is a given number, usually controlled by requiring a consecutive number of most significant bits (MSB) being zeros, for example the first 30 MSBs being zero. The more MSB zeros required on levelHard, the more difficult to solve the puzzle (finding the nonce satisfying the condition). Below gives a binary number with the 15 MSB being zeros and 5 least significant bits (LSB). (MSB) 00000000000000011100000101111110011010101100000 (LSB) 1.3 Signing and verifying a new block The first miner solving the puzzle will create a new block, which includes a block header (storing the digital signature of this new block, which will include the hash value of the block body) and a block body. The block body includes the hash value of the previous block, the found nonce and transactions included in this block. The digital signature is created by encrypting the hash value of this new block with private key. The block is linked to the last block of the existing blockchain and broadcast. The new block will then be verified by others using the winning miners public key and checking the hash values of this and previous blocks.
Public key: (n=0x995361030caa5bf308e272fe07f346600727b5ac0c41107142fd97dd75ec4a197250c038 8b8711b210b2beb300980321913e 9eb21b22f72c3fe8b62addal 3491c6efbf3f4e6c6c60738 da c790af2ca0b806754550fae82c8ea85d3fc0667f1de7a193f23a1d30e8e7f2894f07ce26b5d94 85df5a29fc265fc217dbbb91065b35, e=0x10001) Private key: (n=0x995361030caa5bf308e272fe07f3466c0727b5ac0c41107142fd97dd75ec4a197250c038 858711b210b2beb300980321913e9eb21b22f72c3fe8b62adda13491c6efbf3f4e6c6c60738da c790af2ca0b8067f4550 fae82c8ea85d3fc0667f1de7a193f23a1d30e8e7f2894f07ce26b5d94 85df5a29fc265fc217dbbb91065b35, d=0x24cf1913a7d74042dce7ac6ea30efae19568299bb7c769009ff20ca2ec9c010011eb23f28 f40aa7562bfdebb4f91aef2c091557cflb9d7b82651a2663115flee0c416b1fec516a83657558 068fleebffae9f11b2801830acf2b0af4367fcd26ffe4672c5c5165afaeb5eeb81e6497a04192 1334 76e124b4ce2 a 869a16fc998el) *** First first time use, you need to install module pyeryptodome ### using the following commands (without !) in terminal: pip uninstall crypto #pip install pycryptodome #import necessary modules from Crypto PublicKey import RSA from hashlib import sha512, sha256 import random The following function generateRSAKeys creates the RSA public private key pair. def generateRSAKeys(numBits): keyPair RSA.generate(numBits) return key Pair # Example 1: generating RSA public/private keys. numBits - 1024 key Pair-generateRSAKeynum Bits) print("Public key n"{", hex key Pair.n)"},e-t", hex/key Pair.e). ")") print) print("Private key: "", hex key Pair.n)"), d-{"hex/keyPair.d), ")") print) The following function digital SignRSA digitally sign a message of type "bytes" with RSA private key of keyPair - input msg and key PairRSA #-output: signature (type: int) def digital SignRSA(msg, keyPairRSA) RSA sign the message #msg bytes('A message for signing', 'utf-8) # compute the hash value of the message to be signed with hash algorithm SHA-256 hash Value = int.from_bytes(sha256(msg) digesto. byteorder-'big') #sign (encrypt) the hash value of the message with RSA private key #only the person with RSA private key can perform the operation only the person with RSA private key can perform the operation signaturepowthashValue, key Pair.d, key Pair.) return(hash Value, signature) o Example 2: calling function digitalSignRSA to sign a given message msg - bytes message for signing'. 'utf-8") (hash Value, signature) - digitalSignRSA(meg, keyPair) print"Hash value of message". hashValue) print Signature", he signature) print) with RSA public key of key Pair The following function digital VerifyRSA verify the signature of a message of type "bytes input: maskey PairRSA and signature output: validity (type: boolean) der digital VerifyRSA(mg.key PairRSA.signature) www Verify the digital signature compute the hash value of the message to be signed with hash algorithm SHA-256 hashValue - int.from bytesha256( mgdigesto). byteorderbie) decrypt the signature of the message to obtain the hash value with RSA public key everyone with RSA publiekey can perform the operation hashFromSignature - pow(signature, key Paire, key Pair.n) validit -Thaha huchomionatul validity (hash Value --hashFromSignature) return validity) Example 3verifying a message signature using function digital VerifyRSA Verify the true digital signature with the original message mag-byte 'A message for signing', 'utf-8') validity - digitalVerifyRSamsg, key Pair, signature) prin Signature validity:" validity) prin Verify the true digital signature with a tampered message msgTampered by A message for signing (tampered). wtf-8) validity - digitalVerifyRSA(msgTampered, keyPair, signature) print("Signature validity:", validity) print The following function checkOneNonce will check if one none can solve the puzzle This function can be used to implement the proof-of-work #input numeroseeded (typerint) required number of least significant bits to be zero nonce (type:int)a random number to be checked output: validity (type: boolcon. true or false on the validity of this nonce def checkOneNonce numeros.Needed, nonce Note that a function sha256 copes input of type byte. so we convert random number one to a byte array Byte onvert the random inter to a byteam nilytebytes(stenence), wtf-8) compute the hash of the once hash - int.from_byte(sha256[nByte) diges() bycorder"big) convert the hash value to binary number and extract the needed LSE. hashBinbichash) hashSB inashin-numeros Needed:D #check if the Stare aller if hashSB- print'nRando", nonce, 's hash Ishe', hashSB) validity (hashLSB-0) return validity) if hashSB- println Rand:', nonce." hash Isb:', hush) validity (hah SB-0) return validity) Example 4 smerating a random number as a nonce checking only one nonce with function checkOneNonce. the once may be valid or may be invalid. numer Needed generate a nende a random integer in a specified range) Bone randomrandint(0, 1000000) validity checkOneNocomeros Needed, nonce) print("The validity of this sonce.nonce,"is, validity) print Tusk : Create a RSA public private key pair with 1004 bitskylth24 * Hint you should we Example 1 to generate a RSA key pair, which will be used for Task 3 and Tok 4 You should complete this port to implement Task 1 You should complete this port to implement Task 2 Task 2: Using hash alor SA256 to find anonce which produces a hash value with the least significant bits (LS) being zero Hint you should extend Example with a loop to find a valid once, stop until a valid none is found
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started