Modular Arithmetic
Greatest Common Divisor
Question
There are many tools to calculate the GCD of two integers, but for this task we recommend looking up Euclid's Algorithm.
Try coding it up; it's only a couple of lines. Use a = 12, b = 8 to test it.
Now calculate gcd(a,b) for a = 66528, b = 52920 and enter it below.
Using Repititive Subtraction
Using Modulo
Using math.gcd()
Extended GCD
Using the two primes p = 26513, q = 32321, find the integers u,v such that
p * u + q * v = gcd(p,q)
Enter whichever of u and v is the lower number as the flag.
Knowing that p,q are prime, what would you expect gcd(p,q) to be? For more details on the extended Euclidean algorithm, check out this page.
Modular Arithmetic 1
Calculate the following integers:
11 ≡ x mod 6
8146798528947 ≡ y mod 17
The solution is the smaller of the two integers.
Modular Arithmetic 2
Now take the prime p = 65537. Calculate 273246787654 ^ 65536 mod 65537.
Did you need a calculator?
Answer: 1
Modular Inverting
Question
What is the inverse element: 3 * d ≡ 1 mod 13?
Using Fermat's Little Theorem
Using Extended Euclidean Algorithm
Using Crypto.Util.number.inverse()
Quadratic Residues
Find the quadratic residue and then calculate its square root. Of the two possible roots, submit the smaller one as the flag.
p = 29
ints = [14, 6, 11]
Properties of Quadratic (Non-) Residues
Quadratic Residue * Quadratic Residue = Quadratic Residue
Quadratic Residue * Quadratic Non-residue = Quadratic Non-residue
Quadratic Non-residue * Quadratic Non-residue = Quadratic Residue
Legendre Symbol
Definition
where,
(a / p) = 1 if a is a quadratic residue and a ≢ 0 mod p
(a / p) = -1 if a is a quadratic non-residue mod p
(a / p) = 0 if a ≡ 0 mod p
Which means given any integer a, calculating pow(a, (p-1) // 2,p) is enough to determine if a is a quadratic residue.
Question
Given the following 1024 bit prime and 10 integers, find the quadratic residue and then calculate its square root; the square root is your flag. Of the two possible roots, submit the larger one as your answer.
Formula for Finding Square Root
Modular Square Root
Find the square root of a modulo the 2048-bit prime p. Give the smaller of the two roots as your answer.
Using Sympy
Tonelli-Shanks Algorithm Implementation
Using Sage
Chinese Remainder Theorem
In cryptography, we commonly use the Chinese Remainder Theorem to help us reduce a problem of very large integers into a set of several, easier problems.
Formula
where,
Question
Given the following set of linear congruences:
x ≡ 2 mod 5
x ≡ 3 mod 11
x ≡ 5 mod 17
Find the integer a such that x ≡ a mod 935
Adrien's Signs
Adrien's been looking at ways to encrypt his messages with the help of symbols and minus signs. Can you find a way to recover the flag?
source.py - Given
output.txt - Given
Solution
While the provided source.py script exponentiates the n value with random numbers, it's important to note that since a is a quadratic residue, its powers will also be quadratic residues. However, the script negates the sign of n when b is not equal to 1 (i.e., when b is 0). This implies that we can decode the 8-bit binary code by determining whether n is a quadratic residue. If it is, the function returns 1; otherwise, it returns 0. By doing this we can generate the binary string and then decode it to flag.
Modular Binomials
Rearrange the following equations to get the primes p,q
N = pq
c1 = (2p + 3q)**e1 mod N
c2 = (5p + 7*q)**e2 mod N
Explanation
To get the values of p and q, we have to solve the given equations. First we have to make the equations exponentially same. To do that multiply equation [1] by and equation [2] by , which results in the following form,
Now to get the value of q, we have to eliminate p from equations [3] and [4]. To do that multiply equation [3] by and equation [4] by .
Multiply eqution [6] with -, which results in the following equation,
Solving equations [5] and [7], we get,
From equation [8], we can get q by the following steps:
If a congruence holds modulo a product of two integers, it holds modulo each integer.
The right-hand side of the congruence is a multiple of
q, so the expression is also a multiple ofq.Nis a multiple ofq, meaningqis a divisor of both the expression andN.The only divisors of
Nare1,p,q, andN. Sinceqdivides onlyNandN, it's highly likely that isq, notN.There's no particular reason for
pto divide , making it very unlikely that would beN.Therefore, it's highly probable that equals
q.
After getting q, we can get p by , which we derived from the given, .
Solution
Last updated
Was this helpful?