Алгебра
Алгебра
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 = 0x(without negation) → bit = 1
Decoding Example
First line: (~a∧b∧~c∧~d∧~e∧f∧~g∧~h)
| Variable | Value | Bit |
|---|---|---|
| ~a | NOT a | 0 |
| b | b | 1 |
| ~c | NOT c | 0 |
| ~d | NOT d | 0 |
| ~e | NOT e | 0 |
| f | f | 1 |
| ~g | NOT g | 0 |
| ~h | NOT h | 0 |
Result: 01000100 = 68 = 'D'
Solution
python read-only • copy allowed#!/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
| # | Expression | Bits | Dec | Char |
|---|---|---|---|---|
| 1 | ~a∧b∧~c∧~d∧~e∧f∧~g∧~h | 01000100 | 68 | D |
| 2 | ~a∧b∧~c∧d∧~e∧f∧~g∧h | 01010101 | 85 | U |
| 3 | ~a∧b∧~c∧~d∧~e∧~f∧g∧h | 01000011 | 67 | C |
| 4 | ~a∧b∧~c∧~d∧e∧~f∧g∧h | 01001011 | 75 | K |
| 5 | ~a∧b∧~c∧~d∧~e∧f∧~g∧h | 01000101 | 69 | E |
| 6 | ~a∧b∧~c∧d∧~e∧~f∧g∧~h | 01010010 | 82 | R |
| 7 | ~a∧b∧~c∧d∧e∧~f∧g∧~h | 01011010 | 90 | Z |
| 8 | ~a∧b∧c∧d∧e∧~f∧g∧h | 01111011 | 123 | { |
| 9 | ~a∧b∧~c∧~d∧e∧f∧~g∧~h | 01001100 | 76 | L |
| 10 | ~a∧b∧c∧~d∧e∧f∧g∧h | 01101111 | 111 | o |
| 11 | ~a∧b∧c∧~d∧e∧f∧~g∧~h | 01101100 | 108 | l |
| 12 | ~a∧b∧~c∧~d∧e∧f∧g∧h | 01001111 | 79 | O |
| 13 | ~a∧b∧c∧~d∧~e∧f∧g∧h | 01100111 | 103 | g |
| 14 | ~a∧~b∧c∧~d∧~e∧~f∧~g∧h | 00100001 | 33 | ! |
| 15 | ~a∧b∧~c∧~d∧~e∧~f∧g∧h | 01000011 | 67 | C |
| 16 | ~a∧b∧c∧d∧e∧f∧~g∧h | 01111101 | 125 | } |
| |
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 read-only • copy allowedprint(''.join(chr(sum((0 if '~'+c in l else 1)<<(7-i) for i,c in enumerate('abcdefgh'))) for l in open('algebra.txt')))