-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpartOne.py
More file actions
34 lines (23 loc) · 885 Bytes
/
Copy pathpartOne.py
File metadata and controls
34 lines (23 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from common import *
def single_transformation(v:int, subject_number:int=7) -> int:
return (v * subject_number) % 20201227
def transform(loop_size:int, subject_number:int=7) -> int:
v = 1
for _ in range(loop_size):
v = single_transformation(v, subject_number=subject_number)
return v
def find_loop_size(target_pubkey:int) -> int:
c = 0
v = 1
while True:
c += 1
v = single_transformation(v)
if v == target_pubkey:
return c
def partOne(instr: str) -> int:
pubkey_one, pubkey_two = parse(instr)
loop_size_one = find_loop_size(pubkey_one)
loop_size_two = find_loop_size(pubkey_two)
encryption_key = transform(loop_size_two, subject_number=pubkey_one)
assert encryption_key == transform(loop_size_one, subject_number=pubkey_two), "encryption keys do not match"
return encryption_key