Techras II
Techras II
| Category | Difficulty | Score | Solves | First 🩸 |
|---|---|---|---|---|
| Crypto | Getting There 🤓 | 71 | 69 | TheBacterias |
Code / Description
Overview
This challenge is the second version of Techras challenge with some changes.
- increase the padding schema space from 63 possible characters to 72 characters
- Decrease the number of encryption attempts from 110 to 25
- change the public exponent behaviour
To solve this challenge, we need to
- Compute the probability of the occurrence of the same padding for the flag
- perform common modulus attack with a hope of a low gcd value for possible pairs of public exponents
Challenge Analysis
This challenge is actually the second version of Techras challenge with some differences. It is observable that the conditions have been more difficult, and we can not simply perform the common modulus attack due to several reasons.
- The number of encryptions decreased to 25, and the possible characters of padding increased to 72 characters. This means we can not assure that two identical messages have the same padding
- The public exponent generation is changed. The first one is a 64-bit prime, and for each encryption, it is increased by 2.
According to the new changes, we will no longer be able to solve the challenge like the previous version, but there are still some weaknesses.
Solution
Let's assume the occurrence of the same padding in two ciphertexts among 25 ciphertexts is \(A\). We can do it by the Complement Rule in probability. Let's see what the probability is of not occurring redundant padding in these 25 ciphertexts.
As we see, the probability of not having the same padding for two ciphertexts among 25 ciphertexts is 0.008. So the probability of seeing the same padding for two ciphertexts among 25 total would be:
Although our ciphertexts(25) are much less than the whole possible paddings(72), we can almost % 100% be sure that the flag has been padded with the same padding. This is what is called birthday paradox in cryptography.
Now let's check the public exponent part.
For the first encryption, a 64-bit prime number was generated, and each time it was increased by two for the next encryption. So the public exponents would be like:
We have 25 different public exponents, so we will have 300 possible pairs in total:
We already know that although our number of ciphertexts(25) is much less than the whole possible padding space(72), we still can be sure with a chance of %0.99 that we have the same padding in our ciphertext due to the birthday paradox. So let's see if our public exponents are coprime to each other or not.
These are all the E values we have (25 in total):
If we calculate all possible gcd of two pairs, we will get 8 possible values {1, 3, 5, 7, 9, 11, 13, 17}. It is obvious that although we have an encrypted flag with the same padding, their corresponding public exponents may not be coprime (gcd > 1).
So performing the common modulus attack may lead to calculating different values. Let's see what we may get by performing the same attack. By the Extended gcd, we have:
Let's assume we have found corresponding a,b for an example pair e1,e2, Let's see what will happen if we perform the attack.
If \(gcd(e1, e2)\) is greater than 1, then we will not get directly the $ m $ but $ m $ to a power of a value greater than 1. According to the possible gcd values for all e values, we have
Let's perform the attack to see if we can find a flag padded with the same characters and encrypted twice with two coprime public exponents.
First, we need to read the file and build a dict of E:C values.
Then we need to perform the common modulus attack, but we don't know whether the gcd of two e values is 1 or not. Let's see and implement this function:
And try all possible ciphertext pairs with their corresponding e values:
Let's see what will happen.
As we can see, there is no flag with the same padding and two co-prime e values. So let's assume the gcd of two public exponents for the same padded flags is one of the values {1, 3, 5, 7, 9, 11, 13, 17}. So by performing the attack, we will get one of these values.
We can hope that our $ M $ is not that large, so the values $ m^k \quad k \in {1, 3, 5, 7, 9, 11, 13, 17} $ are less than \(N\). In this case, we can calculate \(M\) by computing the k-th root of the result.
Let's implement the function og calculating the k-th root of a number. You can also use libraries like gmpy.
Now we need to change our function to try all possible gcd values (not only those with value 1, which are coprime)
If we run this code, we will get the flag
We only need to remove the padding and get the original flag with a gcd value of 7 for two ciphertexts that had the same message, but with a gcd value of 7 for the related public exponents.



