PINK CTFMisc
99 / 100
The hint is the bitwise NOT of a GitHub URL for QWERTZ-99, the author's homemade "encryption" tool.
- Competition
PINK CTF
- Category
- MiscHard · estimated
- Source status
- Source-documented · not platform-verified
- Document
- PDF edition3 min read
TL;DR
The hint is the bitwise NOT of a GitHub URL for QWERTZ-99, the author's homemade "encryption" tool. secure.png uses the tool's image format to store a digit string. That string is salted with QWERTZ-98, which multiplies the encoded text by a number derived from a password. Factoring the salted number shows the password is 13371337. Unsalting gives a message that contains a second QWERTZ-99 string, and decoding that with pink.qmap gives the flag.
secure.png → digits "…-98" → ÷ getPw("13371337") → message → inner "…99" string → pink.qmap → flag01
The hint
Every hint byte is ≥ 0x80, and 0x97 is ~'h'. Inverting every byte gives:
https://github.com/QWERTZexe/QWERTZ-99The repo contains main.py (the encoder), img.py (the image format) and some sample .qmap files.
02
How QWERTZ-99 works
.qmap:[QMAP]{c:3}{s:1}(ord|code)(ord|code)…maps each character to a unique 3-digit code.c:3is the code width, ands:1means QWERTZ-98 salting is allowed.Encode: concatenate the codes, then append the terminator
99.QWERTZ-98 salt: drop the
99, multiply the number bygetPw(password), and append-98, wherePython getPw(pw) = int(concat(code(c) for c in pw)) * prod(code(c) for c in pw)Image: one symbol (
0-9,-) per RGBA pixel, hidden behind two random masks.img.decode_imagereverses this.
03
Reading the image
decode_image("secure.png") returns a 620-digit number ending in -98, so the payload is salted and needs a password.
04
Recovering the password
The salted value is C = P · getPw(pw). Brute-forcing all printable passwords up to 3 characters found nothing, so I factored C instead. Trial division gives:
C = 2^6 · 3^14 · 5 · 73 · 137 · 163^4 · 691^2 · 4241 · (589-digit cofactor)Listing the pink.qmap codes that are built only from these primes points to the digits: '1' = 486 = 2·3^5, '3' = 978 = 2·3·163, '7' = 691. That suggests 1337, which is also the challenge's tag.
getPw("1337")dividesC, and its concat part486978978691 = 4241 · 114826451explains the odd 4241 factor. The result is still garbage, though, and the quotient still contains the product of the1337codes a second time.That fits a repeated password. For
13371337, the concat is486978978691 · (10^12 + 1), where10^12 + 1 = 73 · 137 · 99990001, and the codes appear twice. Both 73 and 137 are factors ofC.
getPw("13371337") divides C exactly, and every 3-digit chunk of the quotient is a valid code.
05
Unsalting
Hey, thanks for trusting QWERTZ 99 with your most sensitive data! Here is your sensitive data in case you forgot it: 7275651794079621791841798812894981791841798813944973278472893693272511249906
The inner string
The trailing number ends in 99, so it's another QWERTZ-99 string. Decoding it with pink.qmap (not the repo's default map) gives:
PINK{NiNeTyNiNeQwErTzEs}Solve script
solve.py uses repo/img.py and repo/main.py from the cloned tool:
image : 501387194081198791711765385910090018392855263367757034876879...message: Hey, thanks for trusting QWERTZ 99 with your most sensitive data! Here is your sensitive data in case you forgot it: 7275651794...112499flag : PINK{NiNeTyNiNeQwErTzEs}Flag
Flag
PINK{NiNeTyNiNeQwErTzEs}
Source-documented · not platform-verified
Takeaways
Multiplying by a password-derived number isn't encryption. The password's structure shows up in the factors of the ciphertext.
Building the key from the product of small 3-digit codes leaks which characters are in it through trial division.
