$ cat writeup.md…
$ cat writeup.md…
sekai2026
Task: a Python one-line assertion constrains a SEKAI flag to 67 digits of 6/7 and a divisibility test. Solution: parse precedence, reduce the modulus to 2^67-1, and solve the byte subset directly.
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
English summary: the challenge gives a single Python assertion. The input must match the flag format SEKAI{[67]{67}}, and the big-endian integer representation of the flag must be divisible by the value produced by the final Python expression.
The important part is parsing the Python expression correctly:
int.from_bytes(flag.encode()) % ~(6 + ~7) ** 67
Python exponentiation binds tighter than unary bitwise NOT in this context, so the modulus is:
~((6 + ~7) ** 67)
Now:
~7 = -86 + ~7 = -2(-2) ** 67 = -2^67~(-2^67) = 2^67 - 1So the divisibility condition is:
int.from_bytes(flag.encode(), "big") == 0 mod (2^67 - 1)
The regex fixes the prefix and suffix and leaves exactly 67 variable body bytes, each either ASCII 6 or ASCII 7.
Let:
base = int.from_bytes(b"SEKAI{" + b"6"*67 + b"}", "big") M = 2^67 - 1
Changing a body character from 6 to 7 increases that byte by exactly 1, therefore it adds one power of 256 to the big-endian integer. We need to select positions whose weights sum to -base mod M:
base + sum(selected 256^k) == 0 mod M
Since 256 = 2^8 and gcd(8, 67) = 1, the powers of 256 modulo 2^67 - 1 permute the 67 single-bit weights. That means this subset selection is not a hard subset-sum problem: the target residue directly tells us which positions must be changed to 7.
The following solver starts from the all-6 baseline, computes the required residue, and changes exactly the body positions whose modulo weight appears in that residue.
#!/usr/bin/env python3 import re M = ~(6 + ~7) ** 67 assert M == 2**67 - 1 prefix = b"SEKAI{" suffix = b"}" n = 67 # Start with all body bytes as ASCII '6'. Changing a body byte from '6' to '7' # adds exactly 1 * 256**position to the big-endian integer. base_flag = prefix + b"6" * n + suffix base = int.from_bytes(base_flag, "big") target = (-base) % M body = [ord("6")] * n for i in range(n): # Body byte index i is at absolute byte offset 6+i in a 74-byte string. # Its big-endian exponent is 73-(6+i) = 67-i. weight = pow(256, 67 - i, M) # Because gcd(8,67)=1, each weight is a distinct single bit modulo 2^67-1. if target & weight: body[i] = ord("7") flag = (prefix + bytes(body) + suffix).decode() assert re.match(r"SEKAI{[67]{67}}$", flag) assert int.from_bytes(flag.encode()) % M == 0 print(flag) print("M =", M) print("body length =", len(flag) - len("SEKAI{") - 1)
Running it prints the valid flag and verifies both the regex and divisibility checks.
$ cat /etc/motd
Liked this one?
Pro unlocks every writeup, every flag, and API access. $9/mo.
$ grep --similar