m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-12-25 15:52:55 +0100
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-12-25 15:52:55 +0100
commitb4e25d38821b052390696d37a7c209acdec89006 (patch)
tree708df0fb90a3c493f3c1d812b7bae764879b92bb
parenteeaffa5fa6e5f9f8c42c931eadb9787368bbeac5 (diff)
Add day 25
-rw-r--r--25/a.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/25/a.lua b/25/a.lua
new file mode 100644
index 0000000..f250565
--- /dev/null
+++ b/25/a.lua
@@ -0,0 +1,33 @@
+card_pkey = 8421034
+door_pkey = 15993936
+modulus = 20201227
+
+function step(value, subject)
+ return (value * subject) % modulus
+end
+
+function reverse(pkey, subject)
+ value = 1
+ steps = 0
+ while value ~= pkey do
+ value = step(value, subject)
+ steps = steps + 1
+ end
+
+ return steps
+end
+
+function transform(subject, loop)
+ value = 1
+ for i = 1, loop do
+ value = step(value, subject)
+ end
+
+ return value
+end
+
+card_steps = reverse(card_pkey, 7)
+
+encryption_key = transform(door_pkey, card_steps)
+
+print(encryption_key)