Skip to content

sekai ctf 2026

oneline6ryp7o

how hard can six seven be

challenge description

how hard can six seven be

assert __import__('re').match('SEKAI{[67]{67}}$',flag:=input()) and not int.from_bytes(flag.encode())%~(6+~7)**67

writeup

so the first thing i did split it into the regex part and the math part

the regex part is simple

txt

SEKAI{[67]{67}}$

so the flag starts with SEKAI{ ends with } and has exactly 67 chars inside every inside char is either 6 or 7 67 hahahahahhahahaaha

the real thing is this part

python

not int.from_bytes(flag.encode())%~(6+~7)**67

i checked the weird python ~ stuff first

txt

~7 = -8
6 + ~7 = -2
~(6+~7)**67 = ~((-2)**67)
             = ~(-2**67)
             = 2**67 - 1

so the assert wants

txt

int.from_bytes(flag.encode()) % (2**67 - 1) == 0

that is the main trick wtf looking code but it just becomes mod 2**67 - 1

since the 67 unknown bytes are only 6 or 7 i wont repeat that joke again so i started with all 6s

txt

SEKAI{6666666666666666666666666666666666666666666666666666666666666666666}

then changing one char from 6 to 7 only adds 1 to that byte

the number is big-endian so each byte change adds a power of 256 and

txt

256 = 2^8
mod = 2^67 - 1
2^67 = 1 mod mod

so those 256 powers wrap around cleanly into 67 bit positions ngl this makes the flag recoverable bit by bit

so i used this script

python

import re

M = ~(6+~7)**67
print(6+~7, M, M == 2**67-1)

L = 74
prefix = b'SEKAI{'
suffix = b'}'

const = int.from_bytes(prefix + b'6'*67 + suffix, 'big') % M
target = (-const) % M

print('const', const, 'target', target)

bits = []
for i in range(67):
    pos = (8*(67-i)) % 67
    bits.append((target >> pos) & 1)

flag = prefix + bytes(54+b for b in bits) + suffix
print(flag.decode())

N = int.from_bytes(flag, 'big')
print(re.match(r'SEKAI{[67]{67}}$', flag.decode()) is not None, N % M)
print(len(flag), len(bits), flag.decode()[6:-1].count('7'))

what it does

const is the modulo value for the all-6 flag

target is what i need to add to make the modulo become zero

each bit in target tells me if that position should stay 6 or become 7

python

bytes(54+b for b in bits)

54 is ascii 6 if the bit is 0 it writes 6 if the bit is 1 it writes 7

output

txt

-2 147573952589676412927 True
const 23438612587182973 target 147550513977089229954
SEKAI{6777676667666666677676776776777766777777777776777767777776677666666}
True 0
74 67 39

it returned regex matched and the modulo check passed

and the flag traaaa

txt

SEKAI{6777676667666666677676776776777766777777777776777767777776677666666}

ik this a brainrot challenge but i tried to take it as serious as possible

Discussion

Loading discussion…

Related solves

Keep reading

Complete archive