diff --git a/challenge.py b/challenge.py index dc9e298..ccfbf2e 100644 --- a/challenge.py +++ b/challenge.py @@ -8,9 +8,13 @@ from intro import ( mystery_xor, mystery_key, ) +from public_key_cryptography import ( + modular_exponentiation, + basic_encryption, +) if __name__ == "__main__": - # Intro-level challenge + # Intro-level challenges # fmt: off print(int_to_ascii([99, 114, 121, 112, 116, 111, 123, 65, 83, 67, 73, 73, 95, 112, 114, 49, 110, 116, 52, 98, 108, 51, 125])) print(hex_to_ascii("63727970746f7b596f755f77696c6c5f62655f776f726b696e675f776974685f6865785f737472696e67735f615f6c6f747d")) @@ -25,3 +29,8 @@ if __name__ == "__main__": print(mystery_xor(0x73626960647f6b206821204f21254f7d694f7624662065622127234f726927756d)) print(mystery_key(0x0e0b213f26041e480b26217f27342e175d0e070a3c5b103e2526217f27342e175d0e077e263451150104)) # fmt: on + # fmt: off + # Public-key cryptography course challenges + print(modular_exponentiation()) + print(basic_encryption(12, 17, 23)) + # fmt: on diff --git a/public_key_cryptography.py b/public_key_cryptography.py new file mode 100644 index 0000000..62f5bbc --- /dev/null +++ b/public_key_cryptography.py @@ -0,0 +1,8 @@ +# Challenge PK-crypto-1 +def modular_exponentiation(): + return pow(101, 17, 22663) + + +# Challenge PK-crypto-2 +def basic_encryption(message: int, p: int, q: int): + return pow(message, 0x10001, p * q)