Skip to content

Commit 3488808

Browse files
enigmaxplore
1 parent 090d17e commit 3488808

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Guess the Number Arisu!!
2+
3+
## Description
4+
5+
```text
6+
In the endless dark between stars, a celestial knight named Barrister Selmy guards a secret code, a number hidden somewhere between 0 and
7+
65535, buried deep within the fabric of a black hole. Arisu, an explorer adrift in the void, must uncover it while conserving her dwindling
8+
energy coins. She can send up to 200 quantum probes, each tuned to emit either an AND or OR signal, encoded with unique frequency numbers.
9+
Every probe costs a single coin. Yet the emptiness is cruel, if she sends fewer than 200 signals, the void consumes the rest, draining her
10+
coins equal to what remains unused. Each time, the black hole stirs, and Lord Selmy, or perhaps the worm within echoes back the result of the
11+
operation between the secret code and one of Arisu’s frequencies, chosen at random. With every whisper, she inches closer to decoding the truth
12+
of the number, balancing precision and loss in the abyss of deep space.
13+
```
14+
15+
![image](../images/arisu.png)
16+
17+
## Approach
18+
19+
First thought: try OR operation with 200 0's. But this showed an error saying all input integers must be different.
20+
21+
From the description, we know that the hidden number is *between 0 and 65535*, which means the number **doesn't have more than 16 bits**.
22+
23+
Our input is integers, which can certainly be more than 16 bits.
24+
25+
Idea: Input 200 such numbers whose lowest 16 bits are unset. Taking OR with any of these numbers and then extracting just the 16 bits will give the hidden number.
26+
27+
## Solve Script
28+
29+
```python
30+
from pwn import *
31+
32+
nums = set()
33+
while len(nums) < 200:
34+
# Random 30-bit integer, zero out lower 16 bits
35+
n = (random.randint(0, (1 << 30) - 1) >> 16) << 16
36+
nums.add(n)
37+
38+
r = remote("0.cloud.chals.io", 15985)
39+
r.recvuntil(b"Enter your choice: ")
40+
r.sendline(b"0")
41+
r.recvuntil(b"Enter your choice: ")
42+
r.sendline(b"1")
43+
r.recvuntil(b"Enter operation type (1 for AND, 2 for OR): ")
44+
r.sendline(b"2")
45+
r.recvuntil(b"Enter up to 200 unique numbers (end with -1):\n")
46+
47+
payload = b""
48+
for i in nums:
49+
payload += str(i).encode() + b" "
50+
payload += b"-1"
51+
52+
r.sendline(payload)
53+
s = r.recvline()
54+
# print(s)
55+
num = int(s.decode().strip().split()[-1])
56+
num &= 0xFFFF # extract 16 lower bits
57+
print(num)
58+
r.recvuntil(b"Enter your choice: ")
59+
r.sendline(b"3")
60+
s = r.recvline()
61+
print(s)
62+
r.recvuntil(b"Enter your choice: ")
63+
r.sendline(b"2")
64+
r.recvuntil(b"Enter your guess: ")
65+
r.sendline(str(num).encode())
66+
s = r.recvline()
67+
print(s)
68+
```
270 KB
Loading

0 commit comments

Comments
 (0)