CRT - Chinese Remainder Theorem
The CRT can be applied to solve a theorem of linear congruences if their modules are coprime (). If:
there is one solution , where N = . For example:
there is an integer such that . Challenges
adriens-signs
A custom encryption algorithm that uses modular arithmetic. The encryption is:
- the message is encoded in binary
- consider
- for each byte :
- generate a random integer .
- calculate
- if , then is added to the cyphertext
- else, is added to the cyphertext
notice that is of the form . If we did not have the case of the bit , we would have that each bit of the flag would be in the form:
and if we calculated , weβd have that (this is legendre-symbol, and is never equal to ). But how can we use this? We can also see that the Legendre symbol for , meaning that also , for any value of . This is our first case, meaning we can tell if the byte encrypted was a by calculating its Legendreβs symbol. Can we also tell the case where ? This is equivalent to calculating the value of the following expression:
This is because is odd (). Since the value of is always , we know how to differentiate between the two cases
Modular Binomials
Arrange the following equations to get :
In order to solve this problem, start by elevating to and to :
By calculating the power of the binomial following the Binomial Theorem we would get a polynomial like the following:
but we notice that the terms in the middle are all in the form , where is any combination of and , and and are . Since this terms all contain a product of some power of and , calculating the modulo just cancels them out. So we have:
Since we have , we can apply the crt in reverse (instead of going from a sistem of equations modulo to one equation modulo , we go the opposite way and split the equations) to get the following equations:
the same can be done with :
In these cases, for the equations , the terms containing cancel out, and the same can be said for those . Applying this logic, we get these two equations:
In order to factor , we need a term that we know is divisible by both and , so we can calculate . Such a term can be built as:
We know that is divisible by because both and are. So we get: