From ac83990bc94f900a0cff33c16d63196f7d1496d9 Mon Sep 17 00:00:00 2001 From: boyreau Date: Thu, 5 Nov 2026 12:12:37 +0100 Subject: [PATCH] public_key_cryptography course - challenges 4 - private key computation --- challenge.py | 2 ++ public_key_cryptography.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/challenge.py b/challenge.py index 9f6008c..3d96cd5 100644 --- a/challenge.py +++ b/challenge.py @@ -12,6 +12,7 @@ from public_key_cryptography import ( modular_exponentiation, basic_encryption, Euler_totient, + private_key, ) if __name__ == "__main__": @@ -35,4 +36,5 @@ if __name__ == "__main__": print(modular_exponentiation()) print(basic_encryption(12, 17, 23)) print(Euler_totient(857504083339712752489993810777, 1029224947942998075080348647219)) + print(private_key(857504083339712752489993810777, 1029224947942998075080348647219, 0x10001)) # fmt: on diff --git a/public_key_cryptography.py b/public_key_cryptography.py index 34e1dc3..988e020 100644 --- a/public_key_cryptography.py +++ b/public_key_cryptography.py @@ -11,3 +11,8 @@ def basic_encryption(message: int, p: int, q: int) -> int: # Challenge PK-crypto-3 def Euler_totient(p: int, q: int) -> int: return (p - 1) * (q - 1) + + +# Challenge PK-crypto-4 +def private_key(p: int, q: int, exp: int) -> int: + return pow(exp, -1, (p - 1) * (q - 1))