← Back to Writeups
CUSTOMEasyHardware

Алгебра

XESXOR9/10/20264 min read
#hardware#custom#easy#ascii_decoding#bit_manipulation#boolean_expression_parsing

Алгебра

Platform: duckerz | Category: Hardware | Type: Challenge | Difficulty: Easy | OS: NA | Author: XESXOR | Date: 2026-01-09 | Status: Solved Techniques: ascii_decoding, bit_manipulation, boolean_expression_parsing

Summary

Task: Decode boolean expressions with 8 variables (a-h) connected by AND operations. Solution: Each expression represents a minterm encoding one byte - variables without negation are 1, with negation are 0, converting to ASCII characters.

Алгебра — duckerz CTF

Description

Алгебра логики помогает схемотехникам создавать логические схемы (например, с использованием вентилей И, ИЛИ, НЕ), которые являются основой всех цифровых устройств. Знание логических операций и их упрощение позволяет эффективно проектировать схемы.

Files: algebra.txt

Analysis

The file contains 16 lines with boolean expressions:

(~a∧b∧~c∧~d∧~e∧f∧~g∧~h)
(~a∧b∧~c∧d∧~e∧f∧~g∧h)
(~a∧b∧~c∧~d∧~e∧~f∧g∧h)
...

Expression Structure

  • Each expression contains 8 variables (a, b, c, d, e, f, g, h)
  • Variables are connected with AND operation (∧ - conjunction)
  • The ~ symbol means NOT (negation)
  • Each expression is true only for one combination of variable values ‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Key Observation

8 variables = 8 bits = 1 byte!

  • Variables a-h represent bits from MSB to LSB
  • ~x (with negation) → bit = 0
  • x (without negation) → bit = 1

Decoding Example

First line: (~a∧b∧~c∧~d∧~e∧f∧~g∧~h)

VariableValueBit
~aNOT a0
bb1
~cNOT c0
~dNOT d0
~eNOT e0
ff1
~gNOT g0
~hNOT h0

Result: 01000100 = 68 = 'D'

Solution

python
#!/usr/bin/env python3
"""
Decoding boolean expressions to ASCII characters.
Each expression encodes one byte through 8 variables a-h.
"""
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

with open('algebra.txt', 'r') as f:
    lines = f.readlines()

result = []
for line in lines:
    line = line.strip()
    if not line:
        continue
    
    # Remove parentheses
    line = line.strip('()')
    
    # Split by conjunction symbol
    parts = line.split('∧')
    
    byte = 0
    for part in parts:
        part = part.strip()
        
        # Check for negation
        if part.startswith('~'):
            var = part[1]
            bit_value = 0
        else:
            var = part
            bit_value = 1
        
        # Calculate bit position (h=0, g=1, ..., a=7)
        bit_pos = ord('h') - ord(var)
        byte |= (bit_value << bit_pos)
    
    result.append(byte)
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

flag = ''.join(chr(b) for b in result)
print(flag)

Execution

$ python3 solve.py
DUCKERZ{REDACTED}

Step-by-step Decoding of All Lines

#ExpressionBitsDecChar
1~a∧b∧~c∧~d∧~e∧f∧~g∧~h0100010068D
2~a∧b∧~c∧d∧~e∧f∧~g∧h0101010185U
3~a∧b∧~c∧~d∧~e∧~f∧g∧h0100001167C
4~a∧b∧~c∧~d∧e∧~f∧g∧h0100101175K
5~a∧b∧~c∧~d∧~e∧f∧~g∧h0100010169E
6~a∧b∧~c∧d∧~e∧~f∧g∧~h0101001082R
7~a∧b∧~c∧d∧e∧~f∧g∧~h0101101090Z
8~a∧b∧c∧d∧e∧~f∧g∧h01111011123{
9~a∧b∧~c∧~d∧e∧f∧~g∧~h0100110076L
10~a∧b∧c∧~d∧e∧f∧g∧h01101111111o
11~a∧b∧c∧~d∧e∧f∧~g∧~h01101100108l
12~a∧b∧~c∧~d∧e∧f∧g∧h0100111179O
13~a∧b∧c∧~d∧~e∧f∧g∧h01100111103g
14~a∧~b∧c∧~d∧~e∧~f∧~g∧h0010000133!
15~a∧b∧~c∧~d∧~e∧~f∧g∧h0100001167C
16~a∧b∧c∧d∧e∧f∧~g∧h01111101125}
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Theory

Boolean Algebra in Circuit Design

  • AND (∧) — AND logic gate, output is 1 only if all inputs are 1
  • OR (∨) — OR logic gate, output is 1 if at least one input is 1
  • NOT (~) — inverter, changes 0 to 1 and vice versa

Minterms

Each expression in the task is a minterm — a product of all variables, where each variable appears either directly or with negation. A minterm is true only for one combination of input values.

Alternative Solution (one-liner)

python
print(''.join(chr(sum((0 if '~'+c in l else 1)<<(7-i) for i,c in enumerate('abcdefgh'))) for l in open('algebra.txt')))

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