A-Z.fi

Last modified: 2025-02-11

HTB - Low Logic Writeup by Mcshoothy

Challenge Description

I have this simple chip, I want you to understand how it's works and then give me the output.

Provided files

> Input.csv > chip.jpeg

Chip.jpeg:

Chip.jpeg

Input.csv:

in0,in1,in2,in3
1,0,0,1
1,1,0,0
0,1,1,0
0,0,1,0
1,1,0,1
1,0,0,1
0,0,0,0
0,0,1,0
0,0,0,0

Analyzing the files and the circuit

First, looking at the circuit, it is clear that the columns in the input.csv file match up perfectly with the four logic inputs of the circuit, so it is safe to assume that all we have to do is to figure out the logic of the board and simulate it somehow.

Understanding the circuit

With a little bit of Googling, I figured out that the weird hieroglyphics are just simple BJT NPN transistors. I had no clue what that meant, but luckily, I found a short YouTube video explaining it. # TUTORIAL: The Basics of Transistors (BJT: NPN/PNP) - Switching (Theory)

Basically, a Bipolar Junction Transistor (BJT) is a type of transistor that uses both electrons and holes as charge carriers. In this circuit, NPN transistors act as electronic switches that turn on when a small current is applied to their base.

BJT NPN Symbol

So these transistors have two inputs and a single output:

  • C (Collector): The main current that wants to flow through the transistor.
  • B (Base): The control input—when a small current is applied here, it allows the collector current to pass through.
  • E (Emitter): The exit point for the current once the transistor is activated.

I noticed that IN0 and IN1 are almost identical to IN2 and IN3 so I decided to simulate the circuit to maybe get a better understanding

ss from simulation

[Check put the simulation for yourself]

Breaking Down the Logic

Looking closely at the circuit, I noticed that two pairs of transistors form AND gates—one pair for (IN0 AND IN1), and another for (IN2 AND IN3). These two outputs are then OR'd together, meaning the final logic for the output L is:

L = (IN0 AND IN1) OR (IN2 AND IN3)

This means the light (L) will turn ON (1) if either (IN0 AND IN1) OR (IN2 AND IN3) are both high. Otherwise, it remains OFF (0).

graph LR; In0 -->|1| AND1; In1 -->|1| AND1; In2 -->|0| AND2; In3 -->|0| AND2; AND1 --> |1| OR; AND2 --> |0| OR; OR --> 1;

Solving The Challenge

Obviously we can go through the inputs one by one but let's automate this process with some code;

with open("input.csv") as file:
    lines = file.readlines()[1:]  # Skip the first line (header)

output_bits = []

for line in lines:
    values = line.strip().split(",")
    if values[:2] == ["1", "1"] or values[-2:] == ["1", "1"]:
        output_bits.append("1")
    else:
        output_bits.append("0")

binary_string = "".join(output_bits)
print(binary_string)  # Print the binary output

ascii_output = "".join(chr(int(binary_string[i:i+8], 2)) for i in range(0, len(binary_string), 8))
print(ascii_output)  # Print the decoded ASCII message

Lets run it:

mcshoothy@Mac % python3 new.py

010010011010001011101101100101100110101...

HTB{Flag_In_here}

FunkyHotspot HTB