diff --git a/unit05_key_exchange/src/c_03.py b/unit05_key_exchange/src/c_03.py index d750024..f9bb88b 100644 --- a/unit05_key_exchange/src/c_03.py +++ b/unit05_key_exchange/src/c_03.py @@ -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() \ No newline at end of file +print ('Key: ',keyB,' (A^b) mod p') +print ('Key: ',hashlib.sha256(str(keyB).encode()).hexdigest()