← Back to Writeups
CUSTOMEasyMisc

One or Zero

XESXOR9/2/20262 min read
#misc#custom#easy#binary-digit-to-byte-conversio#elf-file-header-recognition#ascii-code-decoding#linux

One or Zero

Platform: hackerlab.pro | Category: Misc | Type: Challenge | Difficulty: Easy | OS: Linux | Author: XESXOR | Date: 2025-12-23 | Status: Solved Techniques: Binary digit to byte conversion, ELF file header recognition, ASCII code decoding

Summary

Archive one_or_zero.zip contains file bits.txt.

One or Zero - hackerlab.pro

Description

"Ты собираешься действовать или нет?" (Are you going to act or not?)

Archive one_or_zero.zip contains file bits.txt.

Analysis

File Investigation

bash
$ ls -la bits.txt
-rw-r--r-- 1 user user 127616 Dec 23 12:00 bits.txt

$ head -c 100 bits.txt
0111111101000101010011000100011000000010000000010000000100000000...

The file contains 127616 characters — only digits 0 and 1.

Format Recognition

First 32 bits:

01111111 01000101 01001100 01000110
   0x7F     0x45     0x4C     0x46
    DEL       E        L        F

‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

This is the ELF magic header (\x7FELF) — the signature of Linux executable files!

127616 bits / 8 = 15952 bytes — the size of the reconstructed file.

Solution

Step 1: Converting Bits to Bytes

python
#!/usr/bin/env python3

with open('bits.txt', 'r') as f:
    bits = f.read().strip()

# Remove all characters except 0 and 1
bits = ''.join(c for c in bits if c in '01')

# Convert every 8 bits to a byte
data = bytearray()
for i in range(0, len(bits) - 7, 8):
    byte = int(bits[i:i+8], 2)
    data.append(byte)
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

with open('output.bin', 'wb') as f:
    f.write(data)

print(f"Converted {len(bits)} bits to {len(data)} bytes")

Step 2: Verifying the Result

bash
$ file output.bin
output.bin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), 
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, 
for GNU/Linux 3.2.0, not stripped

Got a valid 64-bit ELF executable!

Step 3: Binary Analysis

bash
$ strings output.bin | grep -E "^[0-9 ]+$"
67 79 68 69 66 89 123 108 49 102 101 95 115 95 110 48 116 95 116 104 97 116 95 98 49 110 97 114 121 125

‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Found a sequence of ASCII codes!

Step 4: Decoding ASCII

python
codes = [67, 79, 68, 69, 66, 89, 123, 108, 49, 102, 101, 95, 
         115, 95, 110, 48, 116, 95, 116, 104, 97, 116, 95, 
         98, 49, 110, 97, 114, 121, 125]

flag = ''.join(chr(c) for c in codes)
print(flag)

Hints in the Challenge

  • "one_or_zero" — direct hint at binary data representation
  • "Ты собираешься действовать или нет?" (Are you going to act or not?) — philosophical question about binary choice (yes/no, 1/0)
  • Flag "REDACTED" (life's not that binary) — ironic comment on the challenge ‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Alternative Methods

Python One-liner

python
open('out.bin','wb').write(bytes(int(open('bits.txt').read()[i:i+8],2) for i in range(0,127616,8)))

Using xxd

bash
# First convert bits to hex
python3 -c "print(''.join(f'{int(open(\"bits.txt\").read()[i:i+8],2):02x}' for i in range(0,127616,8)))" | xxd -r -p > output.bin

‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍