← Back to Writeups
CUSTOMEasyHardware

Логика (Logic)

XESXOR9/2/20264 min read
#hardware#custom#easy#binary_to_ascii#boolean_logic#circuit_tracing#gate_analysis

Логика (Logic)

Platform: duckerz | Category: Hardware | Type: Challenge | Difficulty: Easy | OS: NA | Author: XESXOR | Date: 2026-01-09 | Status: Solved Techniques: binary_to_ascii, boolean_logic, circuit_tracing, gate_analysis

Summary

Task: Analyze a digital logic circuit schematic (74LS series TTL ICs) and process input data from Excel. Solution: Trace the circuit to derive the Boolean function, apply it to 368 input rows, and decode the output bits as ASCII.

Логика (Logic) - duckerz CTF

Description

Алгебру логики вспомнили, переходим к схемотехнике.

Files: logic.zip contains logic.pdf (schematic) and logic.xlsx (input data)

Analysis

Archive Contents

  • logic.pdf - digital logic circuit schematic
  • logic.xlsx - Excel file with 368 rows of input data (columns x1-x8) and an empty column for output

Schematic Analysis

The PDF contains a circuit using standard 74LS series TTL ICs:

ICTypeFunction
74LS04DNOTInverter (6 elements)
74LS08DANDLogical AND (4 elements)
74LS32DORLogical OR (4 elements)
74LS86NXORExclusive OR (4 elements)
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Circuit Tracing

Following the connections on the schematic, we get the following logic structure:

Upper branch:

U1A = NOT(x1)
U4A = x2 XOR x3
U5A = U1A AND U4A = NOT(x1) AND (x2 XOR x3)

Middle branch:

U2A = x4 AND x5
U6A = NOT(U2A) = NOT(x4 AND x5) = NAND(x4, x5)

Lower branch:

U7A = NOT(x7)
U3A = x6 OR U7A = x6 OR NOT(x7)
U8A = NOT(U3A) = NOT(x6 OR NOT(x7)) = NOR(x6, NOT(x7))
U9A = x7 XOR x8
U10A = NOT(U9A) = NOT(x7 XOR x8) = XNOR(x7, x8)

Combining:

U11A = U5A OR U6A
U12A = U8A OR U10A
U13A = U11A OR U12A  (output)

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

Full Boolean Function

output = (NOT(x1) AND (x2 XOR x3)) OR NOT(x4 AND x5) OR NOT(x6 OR NOT(x7)) OR NOT(x7 XOR x8)

Solution

python
#!/usr/bin/env python3
"""
Duckerz CTF - Logic
Digital logic circuit solver
"""

import openpyxl

def logic_circuit(x1, x2, x3, x4, x5, x6, x7, x8):
    """
    Implements the logic circuit from the schematic.
    
    ICs used:
    - 74LS04D: NOT (inverter)
    - 74LS08D: AND gate
    - 74LS32D: OR gate
    - 74LS86N: XOR gate
    """
    # Convert to integers
    x1, x2, x3, x4, x5, x6, x7, x8 = int(x1), int(x2), int(x3), int(x4), int(x5), int(x6), int(x7), int(x8)
    
    # Upper branch
    u1a = 1 - x1           # NOT(x1)
    u4a = x2 ^ x3          # x2 XOR x3
    u5a = u1a & u4a        # NOT(x1) AND (x2 XOR x3)
    
    # Middle branch
    u2a = x4 & x5          # x4 AND x5
    u6a = 1 - u2a          # NOT(x4 AND x5) = NAND
    
    # Lower branch
    u7a = 1 - x7           # NOT(x7)
    u3a = x6 | u7a         # x6 OR NOT(x7)
    u8a = 1 - u3a          # NOT(x6 OR NOT(x7))
    u9a = x7 ^ x8          # x7 XOR x8
    u10a = 1 - u9a         # NOT(x7 XOR x8) = XNOR
    
    # Combining
    u11a = u5a | u6a       # Upper OR Middle
    u12a = u8a | u10a      # Lower parts
    u13a = u11a | u12a     # Final output
    
    return u13a
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

def solve():
    # Read input data from Excel
    wb = openpyxl.load_workbook('logic.xlsx')
    ws = wb.active
    
    outputs = []
    
    # Process each row (skip header)
    for row in ws.iter_rows(min_row=2, max_col=8, values_only=True):
        if row[0] is None:
            break
        x1, x2, x3, x4, x5, x6, x7, x8 = row
        result = logic_circuit(x1, x2, x3, x4, x5, x6, x7, x8)
        outputs.append(result)
    
    print(f"Total outputs: {len(outputs)}")
    
    # Convert bits to ASCII (8 bits per character)
    binary_string = ''.join(str(b) for b in outputs)
    print(f"Binary string length: {len(binary_string)}")
    
    # Decode to ASCII
    flag = ''
    for i in range(0, len(binary_string), 8):
        byte = binary_string[i:i+8]
        if len(byte) == 8:
            char = chr(int(byte, 2))
            flag += char
    
    print(f"Flag: {flag}")
    return flag
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

if __name__ == "__main__":
    solve()

Execution

$ python3 solve.py
Total outputs: 368
Binary string length: 368
Flag: DUCKERZ{REDACTED}

74LS Series Reference

ICFunctionNumber of Elements
74LS00NAND4 x 2-input
74LS02NOR4 x 2-input
74LS04NOT6 x inverter
74LS08AND4 x 2-input
74LS32OR4 x 2-input
74LS86XOR4 x 2-input

Solution Methodology

  1. Component identification - determine the types of all ICs on the schematic
  2. Signal tracing - follow the path from inputs to output
  3. Formula construction - write the Boolean function
  4. Code implementation - write the computation function
  5. Data processing - apply to input data
  6. Decoding - convert bits to ASCII ‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍