modular arithmetic course - challenge 1 - gcd
This commit is contained in:
parent
c62223d98c
commit
716ccc14b3
2 changed files with 16 additions and 3 deletions
12
challenge.py
12
challenge.py
|
|
@ -8,6 +8,9 @@ from intro import (
|
|||
mystery_xor,
|
||||
mystery_key,
|
||||
)
|
||||
from modular_arithmetic import (
|
||||
gcd,
|
||||
)
|
||||
from public_key_cryptography import (
|
||||
modular_exponentiation,
|
||||
basic_encryption,
|
||||
|
|
@ -20,8 +23,9 @@ from public_key_cryptography import (
|
|||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Intro-level challenges
|
||||
# fmt: off
|
||||
|
||||
# Intro-level challenges
|
||||
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"))
|
||||
print(hex_to_b64("72bca9b68fc16ac7beeb8f849dca1d8a783e8acf9679bf9269f7bf"))
|
||||
|
|
@ -34,8 +38,7 @@ 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))
|
||||
|
|
@ -49,4 +52,7 @@ if __name__ == "__main__":
|
|||
171731371218065444125482536302245915415603318380280392385291836472299752747934607246477508507827284075763910264995326010251268493630501989810855418416643352631102434317900028697993224868629935657273062472544675693365930943308086634291936846505861203914449338007760990051788980485462592823446469606824421932591,
|
||||
65537
|
||||
))
|
||||
|
||||
# Modular arithmetic course challenge
|
||||
print(gcd(66528, 52920))
|
||||
# fmt: on
|
||||
|
|
|
|||
7
modular_arithmetic.py
Normal file
7
modular_arithmetic.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Challenge 1 - gcd
|
||||
def gcd(a: int, b: int) -> int:
|
||||
while b != 0:
|
||||
r = a % b
|
||||
a = b
|
||||
b = r
|
||||
return a
|
||||
Loading…
Add table
Add a link
Reference in a new issue