public_key_cryptography course - challenges 5 - decryption
This commit is contained in:
parent
ac83990bc9
commit
15131cf4fa
2 changed files with 8 additions and 0 deletions
|
|
@ -13,6 +13,7 @@ from public_key_cryptography import (
|
||||||
basic_encryption,
|
basic_encryption,
|
||||||
Euler_totient,
|
Euler_totient,
|
||||||
private_key,
|
private_key,
|
||||||
|
decode,
|
||||||
)
|
)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
@ -37,4 +38,5 @@ if __name__ == "__main__":
|
||||||
print(basic_encryption(12, 17, 23))
|
print(basic_encryption(12, 17, 23))
|
||||||
print(Euler_totient(857504083339712752489993810777, 1029224947942998075080348647219))
|
print(Euler_totient(857504083339712752489993810777, 1029224947942998075080348647219))
|
||||||
print(private_key(857504083339712752489993810777, 1029224947942998075080348647219, 0x10001))
|
print(private_key(857504083339712752489993810777, 1029224947942998075080348647219, 0x10001))
|
||||||
|
print(decode(857504083339712752489993810777, 1029224947942998075080348647219, 0x10001, 77578995801157823671636298847186723593814843845525223303932))
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
|
||||||
|
|
@ -16,3 +16,9 @@ def Euler_totient(p: int, q: int) -> int:
|
||||||
# Challenge PK-crypto-4
|
# Challenge PK-crypto-4
|
||||||
def private_key(p: int, q: int, exp: int) -> int:
|
def private_key(p: int, q: int, exp: int) -> int:
|
||||||
return pow(exp, -1, (p - 1) * (q - 1))
|
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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue