33 lines
842 B
Python
33 lines
842 B
Python
import secrets
|
|
|
|
from Crypto.Util.number import getPrime
|
|
from Crypto.PublicKey import ECC
|
|
|
|
from classes.Crypto.CommutativeCipher import CommutativeCipher
|
|
from classes.MessageTypes.Introduction import IntroductionMessage
|
|
|
|
p = getPrime(1200)
|
|
q = getPrime(800)
|
|
cipher1 = CommutativeCipher(p, q)
|
|
cipher2 = CommutativeCipher(p, q)
|
|
message = 'Hei på deg'.encode('utf-8 ')
|
|
c1 = cipher1.encode(message)
|
|
c2 = cipher2.encode(c1)
|
|
|
|
d1 = cipher1.decode(c2)
|
|
print(cipher2.decode(d1))
|
|
|
|
key = ECC.generate(curve='p256')
|
|
|
|
test = key.public_key().export_key(format='OpenSSH')
|
|
|
|
seed = secrets.randbits(256).to_bytes(32)
|
|
|
|
key1 = ECC.import_key(test)
|
|
key2 = ECC.import_key(test)
|
|
|
|
print(f'Keys are equal: {key1 == key2}')
|
|
|
|
test = IntroductionMessage('Martin', key.public_key(), seed)
|
|
print(test.generate_and_sign(key))
|
|
print(test.check_signature(key.public_key())) |