Skip to main content
Challenges PRNG-based stream cipher
Cryptography Hard Stream cipher Solves: 10

PRNG-based stream cipher

Author: CyberSamSU
Points
100

The idea of a stream cipher is simple: the generator produces a long keystream, and the message is XORed with it. If the generator is truly cryptographic, this is secure. If it is a simple LCG — the entire cipher becomes as weak as the predictability of this generator.

Here every 4 bytes of the keystream is the complete internal state of the LCG (modulus 232). That is, if we know a part of the plaintext, we can directly read the keystream from that place, and the internal states from the keystream.

Leaked encryption code from the company's internal messenger (A and C remained secret):

M = 2**32
A = <maxfiy>
C = <maxfiy>

def kalit_oqimi(urug, n):
    x, out = urug, b''
    while len(out) < n:
        x = (A * x + C) % M
        out += x.to_bytes(4, 'big')     # har qadamda 4 bayt
    return out[:n]

ct = bytes(p ^ k for p, k in zip(xabar, kalit_oqimi(urug, len(xabar))))

Important information: every message in this messenger starts exactly with the following 16 characters:

SALOM CYBERSAMSU

The attached xabar.hex file contains the ciphertext of one captured message. Fully decrypt it.

Roadmap

  1. XOR the known header with the first 16 bytes of the ciphertext — this yields 16 bytes of the keystream.
  2. Split these 16 bytes into 4-byte chunks and convert them into big-endian numbers: these are consecutive internal states x1, x2, x3, x4.
  3. Find A using the differences: A = (x3 - x2) * (x2 - x1)^(-1) mod 2^32, then C = (x2 - A*x1) mod 2^32. Check with x4.
  4. Starting from x4, step forward to generate the entire keystream and fully decrypt the ciphertext.

Note: the inverse element modulo 2^32 exists only for odd numbers. In this challenge x2 - x1 is odd — so pow(x2 - x1, -1, 2**32) works fine.

Attached files
xabar.hex Log in to download
SHA-256 checksums
xabar.hex: 17d8c49c972fed3bb46e8ed93e89fa6989cce0e77ae2c4d0547a2837715ff76b
Hints 3
Opening a hint reduces the points you get for solving this challenge.
Hint 1 −10 pts Log in
Hint 2 −20 pts Log in
Hint 3 −30 pts Log in
To submit a flag, log in.

First solvers

1. Stiv_084100 11.09.2026
2. Абдул 15.09.2026
3. W.o.X 17.09.2026
4. Лазиз 04.10.2026
5. testrejim 09.10.2026
6. 11111tttt 09.10.2026
7. Mirjaxon Qaxxarov 26.10.2026
8. Odam 04.11.2026
9. arcanum 11.11.2026
10. pentester_uz 12.11.2026