public_key_cryptography course - challenges 3 - Euler's totent.
This commit is contained in:
parent
410a1b7cac
commit
c72e3335ea
2 changed files with 9 additions and 2 deletions
|
|
@ -11,6 +11,7 @@ from intro import (
|
||||||
from public_key_cryptography import (
|
from public_key_cryptography import (
|
||||||
modular_exponentiation,
|
modular_exponentiation,
|
||||||
basic_encryption,
|
basic_encryption,
|
||||||
|
Euler_totient,
|
||||||
)
|
)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
@ -33,4 +34,5 @@ if __name__ == "__main__":
|
||||||
# Public-key cryptography course challenges
|
# Public-key cryptography course challenges
|
||||||
print(modular_exponentiation())
|
print(modular_exponentiation())
|
||||||
print(basic_encryption(12, 17, 23))
|
print(basic_encryption(12, 17, 23))
|
||||||
|
print(Euler_totient(857504083339712752489993810777, 1029224947942998075080348647219))
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,13 @@
|
||||||
# Challenge PK-crypto-1
|
# Challenge PK-crypto-1
|
||||||
def modular_exponentiation():
|
def modular_exponentiation() -> int:
|
||||||
return pow(101, 17, 22663)
|
return pow(101, 17, 22663)
|
||||||
|
|
||||||
|
|
||||||
# Challenge PK-crypto-2
|
# Challenge PK-crypto-2
|
||||||
def basic_encryption(message: int, p: int, q: int):
|
def basic_encryption(message: int, p: int, q: int) -> int:
|
||||||
return pow(message, 0x10001, p * q)
|
return pow(message, 0x10001, p * q)
|
||||||
|
|
||||||
|
|
||||||
|
# Challenge PK-crypto-3
|
||||||
|
def Euler_totient(p: int, q: int) -> int:
|
||||||
|
return (p - 1) * (q - 1)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue