NoBracketsCTF 2025 | Write-up of my challenges
Write-up of my challenges for NoBracketsCTF 2025: encoding, oracle, Gaussian integers, biased OTP and compression attack.

Table of contents
NoBracketsCTF is a CTF for high school students organized by my school’s CTF club: GCC-ENSIBS. It takes place in two phases: qualifications (from October 17 to 19, 2025, TODO teams of 5 participants) and the final (from 10:15 a.m. to 5:15 p.m. on November 19, 2025).
Here is a table summarizing my challenges, their difficulty and their themes:
| Challenge | Tags | Difficulty |
|---|---|---|
| Décode-moi ! | Encoding |
Introduction |
| Double Cipher | Oracle |
Medium |
| it’s complex | Gaussian Integers |
Advanced |
| Roll the dice | OTP, Gaussian distribution |
Medium |
| We love backup | Compression, ChaCha20 |
Advanced |
Challenges for the online qualifications
Décode-moi !
Difficulty: Introduction
Description:
Are you able to decode this secret information?
The challenge provided two files:
chal.py:
from os import getenv
from base64 import b85encode
FLAG = getenv("FLAG", "NBCTF{censuré}")
FLAG = FLAG.encode()
print(b85encode(FLAG).hex())
output.txt:
50436052654d746b437a6f2474376840536d69555660564c465770697b626141392a54574d775545564a257e4664326e3d5a4570315f476231685f4c456f5e304f567b633f28584a7666
We can see that the source code performs two operations on the FLAG:
- A base change from base 256 (byte string) to base 85.
- Then it interprets this base 85 as a byte string (i.e. the b85encode function returns a byte string) and encodes it in base 16: each byte is converted into two hexadecimal numbers.
As the title suggests, there is no cryptography in this challenge, it is just encoding! We can then reverse all these operations; we just need to execute the inverse operations.
Here is how to do it in Python:
from sys import argv
from base64 import b85decode
if len(argv) != 2:
print("Usage : python solve.py <path du fichier output.txt>")
with open(argv[1]) as out:
flag = bytes.fromhex(out.read())
flag = b85decode(flag)
print(flag.decode())
We obtain the following flag: NBCTF{☝️🤓ce-nest-pas-de-la-crypto-mais-de-lencodage}.
Double Cipher
Difficulty: Medium
Description:
My friend only used one cipher to encrypt his data, what a loser! I added a second cipher to improve security 🤌
Source code
from os import getenv, urandom
FLAG = getenv("FLAG", "NBCTF{censuré}")
FLAG = FLAG.encode()
def first_cipher(pt, key):
return bytes([(p^k)for p, k in zip(pt, key)])
def second_cipher(pt, key):
return bytes([(p*k) & 0xff for p, k in zip(pt, key)])
def main():
while True:
_ = input(".")
key = urandom(len(FLAG))
ct_0 = first_cipher(FLAG, key)
ct_1 = second_cipher(FLAG, key)
print(ct_0.hex() + ct_1.hex())
main()
Solving the challenge
The two ciphers used in this challenge are the following:
- An XOR (denoted ), byte by byte, between the key and the plaintext.
- A multiplication modulo 256, byte by byte, between the same key and the same plaintext.
Let be the key and its -th byte; likewise for , the plaintext.
Knowing the ciphertext, we therefore know as well as .
We can ask ourselves the following question: what happens if is 0? Answer: the product will also be 0, so we will detect it directly in the ciphertext. Moreover, is always , so we know that when we detect a null result for the multiplication, the ciphertext from the XOR operation is the plaintext itself.
We can apply this logic in a loop because the script includes an encryption oracle in a while True loop. This allows us to reconstruct entirely.
Note that we will sometimes get false positives. This is because the ring is not integral: it has zero divisors.
A complete implementation of this solution is available in the solve.py file.
it’s complex
Difficulty: Advanced
Description:
I derived my private key using the most complex operations I knew… Impossible to recover the private key from the public key, right?
Challenge overview
The challenge revolves around a key derivation mechanism from a private key (let’s call it ) to a public key (let’s call it ).
Note that these elements are elements of such that (let’s call this field ). We can call these Gaussian integers modulo p (in short, complex numbers but modulo ).
This key derivation consists of (see the source code below):
- A scaling of the norm of ( becomes ). Its ratio varies between and .
- Multiplications of by powers of ( becomes ).
- Multiplications of by “special” numbers ( becomes ).
- Finally,
def derive_pub(y):
# First step
scale = rng.randrange(1, 1337)
y *= GaussianInteger(scale, 0)
# Second step
i = GaussianInteger(0, 1)
i_s = [i**j for j in range(1337)]
specials = [get_special(GaussianInteger) for _ in range(1337)]
for _ in range(rng.randrange(1337)):
y *= rng.choice(i_s)
y *= rng.choice(specials)
# Third step
return α*y + β
The to_bytes function
It is important to note that when the key is converted to bytes (by the .to_bytes function), the following operations are performed:
def to_bytes(self):
s = pow(self.real, 2, self.p) + pow(self.imag, 2, self.p)
if s > self.p: s -= self.p
return s.to_bytes((s.bit_length() + 7) // 8)
The number is therefore mapped to a sequence of bytes corresponding to the norm of the number (rather the square of its norm, but well, it’s “the same” in our context).
“Special” numbers?
Here is the code generating the so-called “special” numbers:
def get_special(GI):
p = GI.p
while True:
a = rng.randrange(p)
maybe_b_squared = (1 - pow(a, 2, p)) % p
is_it_a_square = pow(maybe_b_squared, (p-1)//2, p)
if is_it_a_square != 1:
continue
b_squared = maybe_b_squared
b = pow(b_squared, (p+1)//4, p)
return GI(a, b)
We see that it generates elements of of the form: such that . Indeed, when we are modulo with :
- We check the existence of a square root (called a quadratic residue) by computing the Legendre symbol (
is_it_a_square = pow(maybe_b_squared, (p-1)//2, p)). - The square root is computed by exponentiation
(p+1)/4.
This script therefore generates elements of with a norm equal to 1.
Rotations, and more rotations
The heart of the challenge is understanding that steps 2 and 3 have no impact on the output of to_bytes. Indeed:
- Multiplication by i consists of a rotation in the complex plane: this has no impact on the norm of the number.
- Multiplication by a complex number of modulus 1 has no impact on the norm of the number (proof left to the reader; hint: switch to exponential form).
To solve this challenge, it is therefore enough to recover , because: .to_bytes() == .to_bytes().
Inverting
We can simply subtract from and then multiply the result by the inverse of . The real difficulty here is finding the inverse of ; here is a method:
Let be an element of ; we are looking for such that .
We have obtained our formula for the inverse of an element, so we can perform our “division” by (which here is a multiplication by the inverse).
Decrypting the secret
We can now brute-force the initial scaling to recover the flag:
for i in range(1, 1337):
ii = pow(i, -1, p)
secret = (sk * GaussianInteger(ii, 0)).to_bytes()
flag = dec(ct, secret)
if b"NBCTF" in flag:
print(flag)
A complete implementation of the solution is available in the WU folder on GitHub.
Challenges for the on-site final
Roll the dice
Difficulty: Medium
Description:
I promise, my dice are not loaded 🎲
Source code analysis
This cryptography challenge exposes an encryption oracle over the flag. The flag is encrypted using the One Time Pad (OTP):
from os import getenv
from mac import mac
from rng import rng
from string import ascii_uppercase
alphabet = ascii_uppercase + "É{}-"
assert len(alphabet) == 30
FLAG = getenv("FLAG", "NBCTF{CENSURÉ}")
RND_CONSTS = [rng() for _ in range(rng())]
def encrypt(pt):
ct = ""
for char in pt:
c = alphabet.index(char)
c = c + rng()
ct += alphabet[c % len(alphabet)]
ct += mac(pt).hex()
return ct
print("Bonne chance :)")
while True:
_ = input("")
enc = encrypt(FLAG)
print(enc)
It is well known (see Wikipedia/OTP) that OTP is secure if and only if:
- The key must be at least as long as the plaintext.
- The key must be truly random.
- The key must never be reused in whole or in part.
- The key must be kept completely secret by the communicating parties.
All conditions seem to be met by the challenge, except condition 2; we must check the implementation of the rng function to be sure.
The rng function
from secrets import randbelow
def dice():
# Create a Secure Dice Implementation Using Python's `secrets` Library.
# This library utilizes a Cryptographically Secure Pseudorandom Number Generator (CSPRNG),
# ensuring the randomness is reliable and secure.
# This method leaves no room for vulnerabilities.
return randbelow(6)
def rng():
# To create secure random data mod 30, we need 5 dice.
# Indeed, 1 die => data in range [0 ; 6[
# 5 dice => data in range [0 ; 30[ (= [0*5 ; 6*5[)
# => no random bias, full secure.
NB_DIE = 30 // 6
return sum(dice() for _ in range(NB_DIE))
The dice function returns a number drawn randomly from the set (a kind of 6-sided die starting at zero). No problem here; it uses the Python secrets library, which provides cryptographic randomness (unlike the random library, which implements a Mersenne Twister).
Then the rng function sums several dice to generate a number between 0 and 30. And there… disaster.
For the One Time Pad to be secure, we need a uniform distribution. However, it is obvious that the sum of dice does not provide such a distribution but rather a Gaussian distribution.
Exploiting the Gaussian distribution
The idea to remember is that a Gaussian distribution has the shape of a bell: some bytes will therefore be drawn more often than others. We can then proceed as follows:
- Retrieve the encrypted flag many times.
- For each byte of the ciphertext:
- analyze which byte appears most often;
- deduce that this byte was encrypted with the most frequent key;
- compute the decryption of this byte using that key.
And voilà, we obtain the flag.
However, in our case, the Gaussian is not very “sharp”. In other words, the top 5 most frequent bytes are not clearly distinct (see the analysis in solve.py). We therefore need to perform a slight brute-force by testing the 5 most probable bytes; the associated MAC gives us a stopping condition for our brute-force.
The complete implementation of this approach is available in the solve.py file.
We love backup
Difficulty: Advanced
Description:
Hey, do you want to test my website? We can even make backups! ⚠️ Warning: the final script may take 5-10 minutes to find the solution; I therefore recommend testing locally (use the Dockerfile) and only running remotely when your script works locally.
Analyzing the website
This challenge exposes a website:

After a quick tour of the website’s features and an analysis of the various source files, we note that:
- according to the
Dockerfile, theflag.txtfile is located in the/uploadfolder; - we can upload files to the
/uploadfolder; - we can download an encrypted backup of the entire website.
The backup and its encryption work as follows, for each folder (i.e. static, templates and uploads):
- the script reads all the files, opens them and concatenates their content into a buffer;
- it compresses this buffer into a second compressed buffer;
- finally, it encrypts this compressed buffer and returns it as a file to the user.
The vulnerability
Some prerequisites
To understand the vulnerability, we must first grasp the difference between stream ciphers and block ciphers:
- Stream cipher: data of any size can be encrypted, and we have
len(plaintext) == len(ciphertext). - Block cipher: data must match the block size to be encrypted. If not, padding is added. We therefore obtain
len(plaintext) < len(ciphertext).
In our case, the backup system uses ChaCha20. It is a stream cipher: the size of the encrypted backup is therefore exactly equal to that of the plaintext backup.
Another prerequisite is to have an intuition of how compression algorithms such as gzip work. In particular, one must understand that the size of gzip.compress(b"A"*100) will be smaller than that of gzip.compress(urandom(100)): the lower the entropy, the more efficient the compression. In other words, if the data to be compressed contains repetitive patterns, the compression will be better.
Exploiting it
Let us remember that we can upload files to the server and then download the associated backup. In other words, we can observe the influence of our file on the final size of the compressed backup.
Let’s imagine that the flag is: NBCTF{ABCDEFGH}. Suppose we upload:
- a file containing
NBCTF{A, then download the backup; - a file containing
NBCTF{B, then download the backup.
In which case will the backup be compressed better? In case 1! This means we can determine the first character of the flag by observing which of the two backups is smaller. We can then repeat the operation character by character to reconstruct the entire flag.
A complete implementation of this approach is available in the solve.py file.