# picoCTF 2014: Tick Tock

Math, math, and more math! :)

There was a loth of math in this picoCTF, and Tick Tock was a pretty cool one.

The problem was under the reverse engineering category, but it was definitely mor math related then reverse engineering, as all you had to understand in terms of verersing, was what the python script was doing.

If we remove all the visualization stuff, for spinning the clock all the problem revolves around these functions

the count() function: that is nothing but a modulus operation with some ascii art :)

and the powmod() function: which is nothing but a pow, again with some graphics for displaying the clock.

then the application does the following:

it takes the first argument number we supply, it takes the list named secretz, containing 17 tuples

and cycles over each tuple using the count() function, which as said earlier is nothing but a modulus operation.

it performs the modulus operation between the number we supplied and the second value of the tuple, and checks that the result of the operation matches the first value, if the result is correct it procedes to the next tuple, if it fails, it exits.

for example, if we assume that x is the first argument we submitted it checks that the following statement is true

and if it is, it performs the check for the next tuple.

So the first part of the problem was to find a value x that would satisfy the equivalence for every tuple in the secretz list.

This problem can be solved using the chinese residiant theorem which can be implemented in python as follows:

Once we find the number that satisfies the first part of the problem, the second function comes in play

and what happens here is that the last two modulus operand of the secretz list, are multiplied one another and used as a modulus to compute the following equation

where

• x is our first argument
• y is our second argument
• and N is the number obtained by the multiplication said above

Solving this second part is easy, because there is the Euler’s theorem stating

so.. Walfram Alfa to the rescue!

let’s calculate $\phi(N)$ as this will give us the correct value to submit to the program as second parameter.

Unfortunately the clock script was buggy, and during the last step returned an exception, but in the end the calculated numbers were correct, and scored the flag successfully on the web site.

83359654581036155008716649031639683153293510843035531_32002880064