The final day! Of course it hase to be public-key cryptography…

Part 1

Well the first part is pretty straightforward, just implement the algorithm described to find the secret key (a.k.a. the number of loops):

transform(n, subj) = (n*subj)%20201227

function loops(key, subject=7)
    n = subject
    i = 1
    while n != key
        n = transform(n, subject)
        i += 1
    return i

And then to calculate the encryption key:

function encrypt(key, loops)
    n = 1
    for i in 1:loops
        n = transform(n, key)
    return n

Part 2

Merry Christmas and Happy New Year!

Now I just need to finish days 19, 20, 22, and 23