Skip to content
Adam Omar Saleh

PINK CTF placeholder badge (unofficial)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 placeholder badge (unofficial)PINK CTF
Category
MiscHard · estimated
Source status
Source-documented · not platform-verified
Document
PDF edition3 min read

Brief

The challenge

Category
1337
Points
100
Author
QWERTZ
Files
secure.png, pink.qmap

99, 98, 4ll w31rd numb3rs. 4nd wh4t th3 h3ll 1s 4 .qmap f1l3??

Small help: 978b8b8f8cc5d0d098968b978a9dd19c9092d0aea8baadaba59a879ad0aea8baadaba5d2c6c6

Challenge page
Challenge page

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.

Text
secure.png → digits "…-98" → ÷ getPw("13371337") → message → inner "…99" string → pink.qmap → flag

01

The hint

Every hint byte is ≥ 0x80, and 0x97 is ~'h'. Inverting every byte gives:

Text
https://github.com/QWERTZexe/QWERTZ-99

The 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:3 is the code width, and s:1 means QWERTZ-98 salting is allowed.

  • Encode: concatenate the codes, then append the terminator 99.

  • QWERTZ-98 salt: drop the 99, multiply the number by getPw(password), and append -98, where

    Python
    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_image reverses 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:

Text
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") divides C, and its concat part 486978978691 = 4241 · 114826451 explains the odd 4241 factor. The result is still garbage, though, and the quotient still contains the product of the 1337 codes a second time.

  • That fits a repeated password. For 13371337, the concat is 486978978691 · (10^12 + 1), where 10^12 + 1 = 73 · 137 · 99990001, and the codes appear twice. Both 73 and 137 are factors of C.

getPw("13371337") divides C exactly, and every 3-digit chunk of the quotient is a valid code.

05

Unsalting

Text
Hey, thanks for trusting QWERTZ 99 with your most sensitive data! Here is your sensitive data in case you forgot it: 72756517940796217918417988128949817918417988139449732784728936932725112499

06

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:

Text
PINK{NiNeTyNiNeQwErTzEs}

Solve script

solve.py uses repo/img.py and repo/main.py from the cloned tool:

Text
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.

PDF edition

Writeup PDF

Formatted edition of this walkthrough, built from my source notes · 5 pages.