Update c_03.py

This commit is contained in:
Bill Buchanan
2021-02-25 19:15:08 +00:00
committed by GitHub
parent 14ce2ed5c6
commit 072c19a3e7

View File

@@ -1,10 +1,9 @@
import random
import base64
import hashlib
import sys
g=9
p=1001
p=997
a=random.randint(5, 10)
@@ -13,22 +12,22 @@ b=random.randint(10,20)
A = (g**a) % p
B = (g**b) % p
print 'g: ',g,' (a shared value), n: ',p, ' (a prime number)'
print ('g: ',g,' (a shared value), n: ',p, ' (a prime number)')
print '\nAlice calculates:'
print 'a (Alice random): ',a
print 'Alice value (A): ',A,' (g^a) mod p'
print ('\nAlice calculates:')
print ('a (Alice random): ',a)
print ('Alice value (A): ',A,' (g^a) mod p')
print '\nBob calculates:'
print 'b (Bob random): ',b
print 'Bob value (B): ',B,' (g^b) mod p'
print ('\nBob calculates:')
print ('b (Bob random): ',b)
print ('Bob value (B): ',B,' (g^b) mod p')
print '\nAlice calculates:'
print ('\nAlice calculates:')
keyA=(B**a) % p
print 'Key: ',keyA,' (B^a) mod p'
print 'Key: ',hashlib.sha256(str(keyA)).hexdigest()
print ('Key: ',keyA,' (B^a) mod p')
print ('Key: ',hashlib.sha256(str(keyA).encode()).hexdigest())
print '\nBob calculates:'
print ('\nBob calculates:')
keyB=(A**b) % p
print 'Key: ',keyB,' (A^b) mod p'
print 'Key: ',hashlib.sha256(str(keyB)).hexdigest()
print ('Key: ',keyB,' (A^b) mod p')
print ('Key: ',hashlib.sha256(str(keyB).encode()).hexdigest()