-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay25.java
32 lines (27 loc) · 812 Bytes
/
Day25.java
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
public class Day25 {
public static void main(String[] args) {
long cardPublicKey = 14788856;
long doorPublicKey = 19316454;
long loopSizeCard = transform(cardPublicKey, 7);
long loopSizeDoor = transform(doorPublicKey, 7);
long encryptionKey = transformSubjectKey(cardPublicKey, loopSizeDoor);
System.out.println(encryptionKey);
}
private static long transform(long cardPublicKey, int subjectNumber) {
long result = 1, loopSize = 0;
while(result != cardPublicKey) {
result = result * subjectNumber;
result = result % 20201227;
++loopSize;
}
return loopSize;
}
private static long transformSubjectKey(long subjectNumber, long loopSize) {
long key = 1;
for(int i = 0; i < loopSize; i++) {
key = key * subjectNumber;
key = key % 20201227;
}
return key;
}
}