Skip to content
advent of code 2020

day 25

combo breaker

approach

the two public keys are read from the input. each transform step multiplies by a subject number modulo 20201227. loop_size starts at 1 and steps with subject 7 until it reaches a public key, counting the steps: a brute-force discrete logarithm. encryption_key then applies the card's public key as the subject for the door's loop size.

day 25 has a single part; the second star comes from finishing the others.

the trick

find the secret loop size by brute force, one modular multiplication at a time, then reuse it on the other public key.

python
def loop_size(public):
    v, i = 1, 0
    while v != public:
        i += 1
        v = step(v)
    return i