-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday25.nim
More file actions
35 lines (27 loc) · 781 Bytes
/
day25.nim
File metadata and controls
35 lines (27 loc) · 781 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
35
const
SubjectNumber = 7
Modulo = 20201227
proc transformStep(value: uint64): uint64 =
(value * SubjectNumber) mod Modulo
proc transform(subjectNumber, loopSize: uint64): uint64 =
var value: uint64 = 1
for i in 1..loopSize:
value = (value * subjectNumber) mod Modulo
value
proc findLoopSize(publicKey: uint64): uint64 =
var
loopSize: uint64 = 0
value: uint64 = 1
while value != publicKey:
value = value.transformStep
inc(loopSize)
loopSize
const
CardPublicKey = 2069194
DoorPublicKey = 16426071
let cardLoopSize = CardPublicKey.findLoopSize
let doorLoopSize = DoorPublicKey.findLoopSize
let encryptionKey = DoorPublicKey.transform(cardLoopSize)
# Print results
echo "--- Part 1 Report ---"
echo "Encryption key = " & $encryptionKey