def GenSingleTx(p, q, g, alpha, beta): # Generating single transaction text file. transaction = nineLine(p, q, g, beta) # First nine lines will be hashed and signed. (r, s) = DSA.SignGen(transaction, p, q, g, alpha, beta) transaction += \ "Signature (r): " + str(r) + "\n" + \ "Signature (s): " + str(s) + "\n" return transaction # Returns the transaction string.
def GenSingleTx(p, q, g, alpha, beta): DSA_params = [p, q, g, alpha, beta] m = genMessageToHash(DSA_params) (r, s) = DSA.SignGen(m, p, q, g, alpha, beta) r = 'Signature (r): ' + str(r) s = 'Signature (s): ' + str(s) linesToBeWritten = '\n'.join( [m.rstrip(), r, s]) + '\n' return linesToBeWritten
def TransactionGen(p, q, g): #Generating one transaction (payer_a, payer_b) = DSA.KeyGen(p, q, g) #Generating Keys for Payer (payee_a, payee_b) = DSA.KeyGen(p, q, g) #Generating Keys for Payee transaction = BeforeSign(p, q, g, payer_b, payee_b) #Generating first part of the Transaction (r, s) = DSA.SignGen(transaction, p, q, g, payer_a, payer_b) #Signing the Transaction transaction += \ "Signature (r): " + str(r) + "\n" + \ "Signature (s): " + str(s) + "\n" #Appending the signatures return transaction
def GenTxBlock(p, q, g, count): whole_transaction = "" for i in range(count): transaction = "" transaction += "*** Bitcoin transaction ***\n" line = "Serial number: " x = uuid.uuid4().int line += str(x) + "\n" transaction += line line = "p: " + str(p) + "\n" transaction += line line = "q: " + str(q) + "\n" transaction += line line = "g: " + str(g) + "\n" transaction += line alpha, beta = DSA.KeyGen(p, q, g) line = "Payer Public Key (beta): " + str(beta) + "\n" transaction += line alpha2, beta2 = DSA.KeyGen(p, q, g) line = "Payee Public Key (beta): " + str(beta2) + "\n" transaction += line line = "Amount: " y = random.randint(1, 1000) line += str(y) + " Satoshi\n" transaction += line m = transaction (r, s) = DSA.SignGen(m, p, q, g, alpha, beta) line = "Signature (r): " + str(r) + "\n" transaction += line line = "Signature (s): " + str(s) + "\n" transaction += line whole_transaction += transaction return whole_transaction
def GenSingleTx(p, q, g, alpha, beta): transaction = "" transaction += "*** Bitcoin transaction ***\n" line = "Serial number: " x = uuid.uuid4().int line += str(x) + "\n" transaction += line line = "Payer: " + id_generator() + "\n" transaction += line line = "Payee: " + id_generator() + "\n" transaction += line line = "Amount: " y = random.randint(1, 1000) line += str(y) + " Satoshi\n" transaction += line line = "p: " + str(p) + "\n" transaction += line line = "q: " + str(q) + "\n" transaction += line line = "g: " + str(g) + "\n" transaction += line line = "Public Key (beta): " + str(beta) + "\n" transaction += line m = transaction (r, s) = DSA.SignGen(m, p, q, g, alpha, beta) line = "Signature (r): " + str(r) + "\n" transaction += line line = "Signature (s): " + str(s) + "\n" transaction += line return transaction
def GenTxBlock(p, q, g, count): transaction = "" temp = "" for i in range(count): alpha_payee, beta_payee = DSA.KeyGen(p,q,g) alpha_payer, beta_payer = DSA.KeyGen(p,q,g) temp += "*** Bitcoin transaction ***\n" temp += "Serial number: " + str(random.getrandbits(128)) + "\n" temp += "p: " + str(p) + "\n" temp += "q: " + str(q) + "\n" temp += "g: " + str(g) + "\n" temp += "Payer Public Key (beta): " + str(beta_payer) + "\n" temp += "Payee Public Key (beta): " + str(beta_payee) + "\n" temp += "Amount: " + str(random.randint(0, 1000)) + " Satoshi\n" r, s = DSA.SignGen(temp, p, q, g, alpha_payer, beta_payer); temp += "Signature (r): " + str(r) + '\n' temp += "Signature (s): " + str(s) + '\n' transaction += temp temp = "" return transaction
def GenSingleTx(p, q, g, alpha, beta): serialNum = random.getrandbits(128) payer = "Erdem Bozkurt" payee = ''.join( random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) amount = random.randint(1, 10000) transaction = '''*** Bitcoin transaction *** Serial number: %d Payer: %s Payee: %s Amount: %d Satoshi p: %d q: %d g: %d Public Key (beta): %d ''' % (serialNum, payer, payee, amount, p, q, g, beta) r, s = DSA.SignGen(transaction, p, q, g, alpha, beta) transaction = transaction + '''Signature (r): %d Signature (s): %d ''' % (r, s) return transaction
print "Public key is read from DSA_skey.txt" pkeyFile = open('DSA_pkey.txt', 'r') lines = pkeyFile.readlines() beta = int(lines[3]) pkeyFile.close() print "Public key is read from DSA_pkey.txt" else: print 'DSA_skey.txt or DSA_pkey.txt does not exist' sys.exit() # pick a random message (string) m = random_string(random.randint(1,100)) print "message: ", m (r, s) = DSA.SignGen(m, p, q, g, alpha, beta) print "Signature:" print "r: ", r print "s: ", s if DSA.SignVer(m, r, s, p, q, g, beta)==1: print "Signature verifies:))" else: print "Signature does not verify:((" sys.exit() # Generate a random transaction along with its signature if TxGenOn: if KeyGenOn == 0: if os.path.exists('DSA_pkey.txt') == True and os.path.exists('DSA_skey.txt') == True: skeyFile = open('DSA_skey.txt', 'r')