From b4e25d38821b052390696d37a7c209acdec89006 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Fri, 25 Dec 2020 15:52:55 +0100 Subject: Add day 25 --- 25/a.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 25/a.lua 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) -- cgit v1.2.3