diff --git a/challenge.py b/challenge.py index 3d96cd5..5f5cac1 100644 --- a/challenge.py +++ b/challenge.py @@ -13,6 +13,7 @@ from public_key_cryptography import ( basic_encryption, Euler_totient, private_key, + decode, ) if __name__ == "__main__": @@ -37,4 +38,5 @@ if __name__ == "__main__": print(basic_encryption(12, 17, 23)) print(Euler_totient(857504083339712752489993810777, 1029224947942998075080348647219)) print(private_key(857504083339712752489993810777, 1029224947942998075080348647219, 0x10001)) + print(decode(857504083339712752489993810777, 1029224947942998075080348647219, 0x10001, 77578995801157823671636298847186723593814843845525223303932)) # fmt: on diff --git a/public_key_cryptography.py b/public_key_cryptography.py index 988e020..f53dc9c 100644 --- a/public_key_cryptography.py +++ b/public_key_cryptography.py @@ -16,3 +16,9 @@ def Euler_totient(p: int, q: int) -> int: # Challenge PK-crypto-4 def private_key(p: int, q: int, exp: int) -> int: return pow(exp, -1, (p - 1) * (q - 1)) + + +# Challenge PK-crypto-5 +def decode(p: int, q: int, exp: int, c: int): + pk = private_key(p, q, exp) + return pow(c, pk, p * q)