Solve Day 25#45
Open
manuphatak wants to merge 8 commits into
Open
Conversation
Codecov Report
@@ Coverage Diff @@
## main #45 +/- ##
==========================================
- Coverage 93.62% 93.26% -0.36%
==========================================
Files 33 34 +1
Lines 690 698 +8
Branches 50 52 +2
==========================================
+ Hits 646 651 +5
- Misses 28 30 +2
- Partials 16 17 +1
Continue to review full report at Codecov.
|
Owner
Author
manuphatak
commented
Jan 18, 2021
| where | ||
|
|
||
| part1 :: String -> String | ||
| part1 = show . findEncryptionKey 7 1591838 . readPublicKeys |
Owner
Author
There was a problem hiding this comment.
TODO
I still don't know how to solve equations with mod in them, for example, solve (7^x) mod 20201227 = 13135480 for x.
However, WolframAlpha does:
https://www.wolframalpha.com/input/?i=%287%5Ex%29+mod+20201227%3D13135480
So, for now, I'm hardcoding the value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Day 25: Combo Breaker
You finally reach the check-in desk. Unfortunately, their registration systems are currently offline, and they cannot check you in. Noticing the look on your face, they quickly add that tech support is already on the way! They even created all the room keys this morning; you can take yours now and give them your room deposit once the registration system comes back online.
The room key is a small RFID card. Your room is on the 25th floor and the elevators are also temporarily out of service, so it takes what little energy you have left to even climb the stairs and navigate the halls. You finally reach the door to your room, swipe your card, and - beep - the light turns red.
Examining the card more closely, you discover a phone number for tech support.
"Hello! How can we help you today?" You explain the situation.
"Well, it sounds like the card isn't sending the right command to unlock the door. If you go back to the check-in desk, surely someone there can reset it for you." Still catching your breath, you describe the status of the elevator and the exact number of stairs you just had to climb.
"I see! Well, your only other option would be to reverse-engineer the cryptographic handshake the card does with the door and then inject your own commands into the data stream, but that's definitely impossible." You thank them for their time.
Unfortunately for the door, you know a thing or two about cryptographic handshakes.
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:20201227.The card always uses a specific, secret loop size when it transforms a subject number. The door always uses a different, secret loop size.
The cryptographic handshake works like this:
7according to the card's secret loop size. The result is called the card's public key .7according to the door's secret loop size. The result is called the door's public key .If you can use the two public keys to determine each device's loop size, you will have enough information to calculate the secret encryption key that the card and door use to communicate; this would let you send the
unlockcommand directly to the door!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 be8, because transforming the initial subject number of7with a loop size of8produces5764801.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 is11, because transforming the initial subject number of7with a loop size of11produces17807724.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 of8(the card's loop size) produces the encryption key,14897079. (Transforming the subject number of5764801(the card's public key) with a loop size of11(the door's loop size) produces the same encryption key:14897079.)What encryption key is the handshake trying to establish?
Part Two
The light turns green and the door unlocks. As you collapse onto the bed in your room, your pager goes off!
"It's an emergency!" the Elf calling you explains. "The soft serve machine in the cafeteria on sub-basement 7 just failed and you're the only one that knows how to fix it! We've already dispatched a reindeer to your location to pick you up."
You hear the sound of hooves landing on your balcony.
The reindeer carefully explores the contents of your room while you figure out how you're going to pay the 50 stars you owe the resort before you leave. Noticing that you look concerned, the reindeer wanders over to you; you see that it's carrying a small pouch.
"Sorry for the trouble," a note in the pouch reads. Sitting at the bottom of the pouch is a gold coin with a little picture of a starfish on it.
Looks like you only needed 49 stars after all.
Link
https://adventofcode.com/2020/day/25