mirror of
https://github.com/billbuchanan/appliedcrypto.git
synced 2026-02-21 19:27:58 +00:00
Update c_03.py
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user