Lesson 8. The card — into a chip with 8 legs
In picturesEverything built in seven lessons is the card's computer. We fold it into one chip with eight legs, make a second card with another identity — and swap the cards in the tester, like in an ATM.
8.1. The idea: a card is what is inside
From outside a card has only what the terminal gives it: power, ground, reset, clock and the data wire. Everything else — processor, memory, program, identity — is inside. The card's inputs are Input ports, the data wire IO is an Output port: the card pulls it itself. If you make ground or FAC an output, the editor shows a lightning bolt: two outputs on one wire.
8.2. The idea: two cards — one program
The second card is a copy of the chip (button ⧉ in the library) with another matrix. The program, the processor, the memory are the same. From outside the cards look the same; the difference is 29 transistors out of 6,500. They answer the same challenge differently — that is how the bank tells cards apart.
8.3. Building
The same project as in lesson 7.
| C1 VCC | GND C5 |
|---|---|
| C2 RST | FAC C6 |
| C3 CLK | IO C7 |
| C4 — | — C8 |
Step 1. What stays outside
Outside the chip is what belongs to the terminal, not to the card:
Clock(clockCLK), switchesRSTandFAC;- the whole adapter of lesson 5: the resistor and the
TPULLtransistor on theIOwire, switchesT0–T7, buttonSEND, everything fromsendStoWTB, lampssr0–sr7andlamp; PowerandGround.
Everything else is the card: from DEC16 of lesson 1 to the matrix transistors of lesson 6, together with the display and lamps A and PC (they end up inside the chip — you can see them if you dive into it with a double click).
Step 2. Eight legs — ports
Next to the card put 8 ports. Everything the card gets from the terminal (power, ground, reset, clock, FAC) is an Input port: C1–C6 in a column from top to bottom (the order from top to bottom = the order of the chip's legs). IO is data both ways, the card pulls this wire itself — Output port C7, and an empty C8 below it. The port name — double-click on it. A label goes on the port (the net inside the card):
| Part | Port name | Label | What |
|---|---|---|---|
| Input port | C1 | VCC | power |
| Input port | C2 | RST | reset |
| Input port | C3 | CLK | clock |
| Input port | C4 | — | not used |
| Input port | C5 | GND | ground |
| Input port | C6 | FAC | factory preparation |
| Output port | C7 | IO | data |
| Output port | C8 | — | not used |
C4 and C8 are not connected to anything — the same on real cards: these contacts exist but are not used.
A chip draws inputs on the left and outputs on the right, so the legs will stand like this: C1–C6 on the left, C7 and C8 on the right — not like on the pad, 4 and 4. If you make GND or FAC an output (Output port), the editor shows a red lightning bolt: the chip "drives" a wire that is already driven by ground and a switch — two outputs on one wire.
Step 3. Fold
Select the card and the 8 ports with a frame (without what is in step 1) → Ctrl+G → name CARD. The program in the ROM is baked into the chip by itself.
Step 4. Insert the card into the terminal
| Part | Pin | Label |
|---|---|---|
| CARD | C1 C2 C3 C4 C5 C6 C7 C8 | VCC RST CLK — (do not connect) GND FAC IO — (do not connect) |
8.4. Checking
The same as in lesson 7 — but now through the chip's 8 legs. First the factory preparation: after folding the chip starts anew.
| № | What to do | Lamps (● lit) | What it is |
|---|---|---|---|
| 1 | Clock — MAX | ||
| 2 | switch FAC and RST on, wait a second, switch both off | ○○●●●○●● 59 | the card chip said hello |
| 3 | switches T7…T0 = 0100 1110, press SEND | ○○○○○○○● 1 | N — account 1 |
| 4 | switches T7…T0 = 0101 0000, press SEND | ○○○○○○○○ go off | the byte went, the card waits for the next one |
| 5 | switches T7…T0 = 0001 0010, press SEND | ○○○○○○○○ go off | the byte went, the card waits for the next one |
| 6 | switches T7…T0 = 0011 0100, press SEND | ●○○●○○○○ 144 | P 12 34 — PIN correct |
| 7 | switches T7…T0 = 0100 0001, press SEND | ○○○○○○○○ go off | the byte went, the card waits for the next one |
| 8 | switches T7…T0 = 1010 0101, press SEND | ○○○○○○○○ go off | the byte went, the card waits for the next one |
| 9 | switches T7…T0 = 0011 1100, press SEND | ○●●○●○○○ 104 | A A5 3C — first byte of the answer ($68) |
| 10 | switches T7…T0 = 0101 0010, press SEND | ●●●●○●●● 247 | R — second byte ($F7) |
Step 5. A second card: a copy with another identity
In the library, chip CARD has the button ⧉ (copy) → name CARD2. The copy is the same device: processor, program in the ROM, memory. Only the identity will differ — the matrix transistors.
CARD2 → "Edit". Find the matrix: 7 rows pr0–pr6 (bytes 16–22) and 8 columns pb7–pb0 (bits). Go down the rows from top to bottom and in each cell do what it says:
| Row | Byte: was → now | pb7 | pb6 | pb5 | pb4 | pb3 | pb2 | pb1 | pb0 | What |
|---|---|---|---|---|---|---|---|---|---|---|
| pr0 | 01 → 02 | · | · | · | · | · | · | + | ✕ | account number |
| pr1 | 12 → 43 | · | + | · | ✕ | · | · | ● | + | PIN, digits 1–2 |
| pr2 | 34 → 21 | · | · | ● | ✕ | · | ✕ | · | + | PIN, digits 3–4 |
| pr3 | 5A → 21 | · | ✕ | + | ✕ | ✕ | · | ✕ | + | key, byte 1 |
| pr4 | C3 → 9F | ● | ✕ | · | + | + | + | ● | ● | key, byte 2 |
| pr5 | 17 → E4 | + | + | + | ✕ | · | ● | ✕ | ✕ | key, byte 3 |
| pr6 | 8E → 3B | ✕ | · | + | + | ● | ✕ | ● | + | key, byte 4 |
● — there is a transistor and it stays, do not touch · ✕ — delete · + — place a new one · · — empty and stays empty. A new transistor is nmos: gate on row pr, drain on column pb, source on GND.
In total: delete 14, place 15, keep 8 — the CARD2 matrix has exactly 23 transistors.
Save the chip.
Step 6. Take one card out, insert another
Put CARD2 on the table next to CARD. The card inserted into the terminal is the one whose legs carry the terminal's labels (step 4). Only one is ever inserted: two cards on the same labels are two outputs on the IO wire.
| Action | What to do |
|---|---|
| take out CARD | remove the labels VCC, RST, CLK, GND, FAC, IO from the legs of CARD (delete the labels or detach the wires) |
| insert CARD2 | hang the same 6 labels on the same legs of CARD2: C1 VCC, C2 RST, C3 CLK, C5 GND, C6 FAC, C7 IO |
The new card has not "come from the factory" yet: the first time — FAC and RST. Then the check:
| № | What to do | Lamps (● lit) | What it is |
|---|---|---|---|
| 1 | switch FAC and RST on, wait a second, switch both off | ○○●●●○●● 59 | greeting |
| 2 | switches T7…T0 = 0100 1110, press SEND | ○○○○○○●○ 2 | N — now account 2 |
| 3 | switches T7…T0 = 0101 0000, press SEND | ○○○○○○○○ go off | the byte went, the card waits for the next one |
| 4 | switches T7…T0 = 0001 0010, press SEND | ○○○○○○○○ go off | the byte went, the card waits for the next one |
| 5 | switches T7…T0 = 0011 0100, press SEND | ○●●○○○●○ 98 | P 12 34 — the PIN of card 1 does not fit |
| 6 | switches T7…T0 = 0101 0000, press SEND | ○○○○○○○○ go off | the byte went, the card waits for the next one |
| 7 | switches T7…T0 = 0100 0011, press SEND | ○○○○○○○○ go off | the byte went, the card waits for the next one |
| 8 | switches T7…T0 = 0010 0001, press SEND | ●○○●○○○○ 144 | P 43 21 — its own PIN |
| 9 | switches T7…T0 = 0100 0001, press SEND | ○○○○○○○○ go off | the byte went, the card waits for the next one |
| 10 | switches T7…T0 = 1010 0101, press SEND | ○○○○○○○○ go off | the byte went, the card waits for the next one |
| 11 | switches T7…T0 = 0011 1100, press SEND | ●●●○●○●○ 234 | A A5 3C — a different answer ($EA) |
| 12 | switches T7…T0 = 0101 0010, press SEND | ●●○●●●○● 221 | R — ($DD) |
To the same challenge A5 3C card 1 answered 68 F7, card 2 — EA DD. From outside the chips are the same; the difference is 29 transistors of the matrix out of 6,500. That is how the bank tells cards apart: not by their look, but by the answer that only its own card can give.
Insert CARD back (the labels again on its legs), FAC and RST — and N answers 1 again: the identity of card 1 has not gone anywhere, it is in its transistors.
Step 7. The tester — into a chip too
The card tester (the adapter of lesson 5) is a device too: electronics inside, a panel outside. Let us fold it as well, so that the table holds two clear devices: the card and the tester. Lamps and displays inside a chip are not visible on the canvas, so everything you look at and press stays outside: switches T0–T7, button SEND, lamps sr0–sr7 and lamp, the display.
Next to the tester put the ports (port name = label, double-click to rename):
| Part | Port name and label |
|---|---|
| Input port | CLK |
| Input port | RST |
| Input port | SEND |
| Input port | T0 |
| Input port | T1 |
| Input port | T2 |
| Input port | T3 |
| Input port | T4 |
| Input port | T5 |
| Input port | T6 |
| Input port | T7 |
| Output port | sr0 |
| Output port | sr1 |
| Output port | sr2 |
| Output port | sr3 |
| Output port | sr4 |
| Output port | sr5 |
| Output port | sr6 |
| Output port | sr7 |
| Output port | lamp |
| Output port | IO |
IO is an output: the tester pulls the wire itself. Select with a frame the tester's electronics (the resistor, transistor TPULL, everything from NOT(RST) = nRT to DFF → WTB) and the ports — without the switches, the button, the lamps and the display → Ctrl+G → name TERM. The legs of TERM go to labels with the same names:
| Part | Pin | Label |
|---|---|---|
| TERM | CLK RST SEND T0 T1 T2 T3 T4 T5 T6 T7 sr0 sr1 sr2 sr3 sr4 sr5 sr6 sr7 lamp IO | CLK RST SEND T0 T1 T2 T3 T4 T5 T6 T7 sr0 sr1 sr2 sr3 sr4 sr5 sr6 sr7 lamp IO |
Check — any row of the "Check by hand" step: N → display 1. Inside the tester — 1,729 transistors and a resistor.
⚠ A common mistake. When rewiring card 2, the transistors that the cards share (● in the grid) were deleted too. The account number is then correct, but the PIN and the key are not. The card 2 matrix must have exactly 23 transistors.
Lesson 8 paste (Cmd+I)
The card's eight ports — put them next to the card, then select the card together with them and press Ctrl+G.
# Lesson 8 — the card's 8 legs: put the ports next to the card, select the card with them and press Ctrl+G -> CARD.portIn{name=C1}(VCC)portIn{name=C2}(RST)portIn{name=C3}(CLK)portIn{name=C4}(nc4)portIn{name=C5}(GND)portIn{name=C6}(FAC)portOut{name=C7}(IO)portOut{name=C8}(nc8)Stuck? Something doesn't work →