Your task is to reverse-engineer the cryptographic handshake the card does with the door and then inject your own commands into the data stream.

The handshake used by the card and the door involves an operation that **transforms** a **subject number**. To transform a subject number, start with the value 1. Then, a number of times called the **loop size**, perform the following steps:

- Set the value to itself multiplied by the
**subject number**. - Set the value to the remainder after dividing the value by
**20201227**.

The cryptographic handshake works like this:

- The
**card**transforms the subject number of**7**according to the**card**'s secret loop size. The result is called the**card's public key**. - The
**door**transforms the subject number of**7**according to the**door**'s secret loop size. The result is called the**door's public key**. - The card and door use the wireless RFID signal to transmit the two public keys (your puzzle input) to the other device. Now, the
**card**has the**door**'s public key, and the**door**has the**card**'s public key. Because you can eavesdrop on the signal, you have both public keys, but neither device's loop size. - The
**card**transforms the subject number of the**door**'s**public key**according to the card's loop size. The result is the**encryption key**. - The
**door**transforms the subject number of the**card**'s**public key**according to the door's loop size. The result is the same**encryption key**as the card calculated.

For example, suppose you know that the card's public key is 5764801. With a little trial and error, you can work out that the card's loop size must be **8**, because transforming the initial subject number of 7 with a loop size of 8 produces 5764801.

Then, suppose you know that the door's public key is 17807724. By the same process, you can determine that the door's loop size is **11**, because transforming the initial subject number of 7 with a loop size of 11 produces 17807724.

At this point, you can use either device's loop size with the other device's public key to calculate the **encryption key**. Transforming the subject number of 17807724 (the door's public key) with a loop size of 8 (the card's loop size) produces the encryption key, **14897079**. (Transforming the subject number of 5764801 (the card's public key) with a loop size of 11 (the door's loop size) produces the same encryption key: **14897079**.)

What encryption key is the handshake trying to establish?

## VP 35.1: Handshake (15 pts extra)

Use this data:What encryption key does the handshake establish?Card's public key: 10212254 Door's public key: 12577395That number is the flag.

Hint 1: The loop numbers are larger than 1 million.

Hint 2: Use thepowfunction.

Posted 10-12-24