Five push-buttons control everything. All are active-LOW with internal pull-ups — press once to trigger, release to idle. Two LEDs show the current mode at a glance.
| Button | In normal / typing screen | In any menu |
|---|---|---|
| MODE | Cycle PASSTHROUGH → ENCRYPT → DECRYPT | Same — always cycles mode |
| SELECT | Cycle selected rotor slot (R → M → L) | Confirm highlighted item / enter sub-menu |
| UP | Increment selected rotor position | Move cursor up / change value forward |
| DOWN | Decrement selected rotor position | Move cursor down / change value backward |
| ENTER | Open config menu (all modes) | Go back one level / cancel without applying |
| J5 Pin | Signal | GPIO | Direction | Active state | Function |
|---|---|---|---|---|---|
| J5 pin 2 | BTN_MODE | PD2 | Input | LOW (WPU) | Cycle operating mode |
| J5 pin 4 | LCD_TX | PP1 | Output | UART TX | RS-232 to NHD-0420D3Z (9 600 baud) |
| J5 pin 7 | BTN_SELECT | PQ0 | Input | LOW (WPU) | Confirm / cycle rotor slot |
| J5 pin 8 | BTN_UP | PP4 | Input | LOW (WPU) | Increment / scroll up |
| J5 pin 9 | BTN_DOWN | PN5 | Input | LOW (WPU) | Decrement / scroll down |
| J5 pin 10 | BTN_ENTER | PN4 | Input | LOW (WPU) | Open config / go back |
| J5 (PB4) | LED_GREEN | PB4 | Output | HIGH = on | ENCRYPT mode indicator |
| J5 (PB5) | LED_RED | PB5 | Output | HIGH = on | DECRYPT mode indicator |
The NHD-0420D3Z is a 20-character × 4-line display operating in RS-232 mode (R1 = open, R2 = open on the back of the PCB). It receives commands and characters over a single serial line from UART6 at 9 600 baud.
| LCD Pin | Signal | LaunchPad | GPIO / Peripheral | Notes |
|---|---|---|---|---|
| LCD RX | Serial data in | J5 pin 4 | PP1 — UART6 TX | RS-232, single wire, 9 600 baud 8N1 |
| LCD VDD | +5 V power | J5 VCC rail | — | LCD requires 5 V |
| LCD GND | Ground | J5 GND | — | Common ground with LaunchPad |
| R1 (back) | Mode select | — | — | Leave open for RS-232 mode |
| R2 (back) | Mode select | — | — | Leave open for RS-232 mode |
| UART6 peripheral | TX pin | Baud | Format | Boot delay |
|---|---|---|---|---|
| SYSCTL_PERIPH_UART6 | PP1 | 9 600 | 8N1 | 500 ms after power-on |
| Command byte | Prefix | Function |
|---|---|---|
| 0x51 | 0xFE | Clear screen and reset cursor to home |
| 0x45 + addr | 0xFE | Set cursor to DDRAM address |
| 0x41 | 0xFE | Display on |
| 0x53 + level | 0xFE | Set backlight brightness (0–8) |
| LCD line | DDRAM start address | Columns |
|---|---|---|
| Line 1 | 0x00 | 0–19 |
| Line 2 | 0x40 | 0–19 |
| Line 3 | 0x14 | 0–19 |
| Line 4 | 0x54 | 0–19 |
Line 1: Fixed title. Line 2: Mode — PASSTHROUGH / ENCRYPT / DECRYPT.
Line 3: Rotor types. [III] = selected slot. Line 4: Positions. >C< = editable. PB:X+Y = Stage1+Stage2 pairs.
Line 1: ENC/DEC + live rotor positions (update each char). Line 2: Input stream. Line 3: Output stream. Wraps at col 20. Line 4: Rotor types + plugboard pair counts.
| Mode | LED | MITM gate | What happens when you type |
|---|---|---|---|
| PASSTHROUGH | Both off | SW_PASS HIGH — keyboard → typewriter direct | Characters pass through unchanged. |
| ENCRYPT | Green on | SW_PASS LOW — intercept active | MSP432 scans, encrypts, injects output on FPC2. Typewriter prints ciphertext. |
| DECRYPT | Red on | SW_PASS LOW — intercept active | Same path — Enigma is self-inverse. Type ciphertext, typewriter prints plaintext. |
Boot blink — confirms the MCU started and GPIO is working.
SW_PASS (U7) HIGH, OE_245 HIGH, INH_4051 HIGH. Typewriter works normally.
Default: PASSTHROUGH · Rotors I-II-III · Reflector B · Positions AAA · No plugboard.
Serial · COM port · 115 200 baud · 8N1. Should see banner then "Ready."
Press ENTER from any screen to open config. Press ENTER again inside any sub-menu to go back one level without applying changes.
UPDOWN scroll I–V. SELECT confirms and advances to Mid, then Left. Final SELECT on Left applies all three.
PuTTY confirms: Rotors: L=I M=II R=III
UPDOWN pick A/B/C. SELECT applies. PuTTY: Reflector: B
These positions are restored at the start of every new message. Final SELECT on Left applies all three.
PuTTY: Ring: L=A M=A R=A
Two independent stages. Stage 1 substitutes before the rotors. Stage 2 substitutes after. Each stage holds 0–13 pairs.
Number beside each stage = active pairs. ENTER returns to config.
Preset — 31 historical day sheets. Manual — enter pairs on-screen. Physical plug — read pairs from hardware jacks live. Clear — scroll down past Physical plug to reach it.
PuTTY confirms pairs and count. ENTER cancels.
Used letters are skipped automatically. After all pairs, auto-applied. PuTTY: Stage1: BF SD ... (05 pairs)
Twenty-six 3.5 mm jacks, one per letter A–Z, are wired directly to GPIO pins on the MSP432E401Y with internal pull-ups. Mono patch cables connect any two jacks to create a substitution pair. Up to 13 simultaneous pairs are tracked in real time.
A mono (TS) cable has two ends. Both ends always move together — inserting a cable inserts both ends simultaneously. You cannot unplug one end while the other stays in. This governs all state transitions below.
| # | Event | Before | After |
|---|---|---|---|
| T1 | Insert plug — no waiting pair exists | Board empty or all pairs PAIRED | New pair opens. Jack = Slot 1. WAITING. |
| T2 | Insert plug — a waiting pair exists | Pair N has Slot 1, no Slot 2 | Jack fills Slot 2 of oldest waiting pair. PAIRED. |
| T3 | Remove Slot 2 from a PAIRED pair | Pair N: Slot1 ↔ Slot2 PAIRED | Slot 2 cleared. Slot 1 unchanged. Pair → WAITING. |
| T4 | Remove Slot 1 from a PAIRED pair | Pair N: Slot1 ↔ Slot2 PAIRED | Slot 2 promoted to Slot 1. Pair → WAITING. |
| T5 | Remove only jack from a WAITING pair | Pair N: Slot 1 only | Pair dissolved. Pairs below shift up. |
When a cable is pulled, both ends go LOW in the same 50 ms poll window. Removals fire in A→Z order, so both sub-cases dissolve the pair correctly:
| Cable ends | A→Z order fires | Result |
|---|---|---|
| Slot1 letter < Slot2 letter e.g. A↔C, pull both | T4 on A → promotes C to Slot1 T5 on C → only jack → dissolve | Pair dissolves ✓ |
| Slot2 letter < Slot1 letter e.g. C↔A where C=slot2 | T3 on A → clears Slot2, C stays Slot1 WAITING T5 on C → only jack → dissolve | Pair dissolves ✓ |
New plugs always complete the pair that has been waiting the longest. The pairs array is ordered by insertion time — index 0 is the oldest. Example: A waiting, C waiting, B inserted → B goes to A's pair because A waited longer.
Press DOWN until "Physical plug" is highlighted. Press SELECT. The firmware calls plugboard_hw_init(), enables all jack GPIO peripherals, sets all 26 pins as input+WPU, runs an initial drive-low scan, and displays the result immediately.
Line 1 shows stage and pair count. Lines 2–3 blank. Firmware rescans every ~20 ms loop tick.
LCD updates when pair count changes. Check the display matches your cables. Press SELECT to apply. PuTTY confirms: Stage1: AB CD EF GH IJ KL MN OP (07 pairs)
Green = WAITING for partner. Red = PAIRED. Small number = pair index. Simulates all 5 transitions exactly as the firmware does.
All jacks configured as GPIO input with 2 mA weak pull-up (WPU). No plug → pin HIGH. Cable between two jacks short-circuits them. Note: Z uses PG1, same pin as SW_COL_IN (MITM CD4066). Safe because physical plug scanning only occurs during config when MITM is in passthrough.
All pairs in the selected stage are immediately removed. PuTTY confirms: Stage cleared
Press MODE until green LED lights. Check line 4 shows expected PB counts. MITM switches to intercept: SW_PASS LOW, CD4051 enabled, 74LVC245 active B→A.
MITM intercepts each key, MSP432 encrypts through Enigma, injects the output on FPC2 — the typewriter prints the ciphertext character. Line 1 positions advance after every character.
Rotors reset to Grundstellung. Message saved to history. LCD returns to normal. PuTTY: --- message end (rotors reset) ---
Enigma is self-inverse — the same settings decrypt what they encrypted. Receiver must use identical rotor selection, reflector, ring position, and plugboard pairs on both stages.
MITM intercepts, MSP432 decrypts, typewriter prints plaintext on FPC2. Line 2 = ciphertext, Line 3 = recovered plaintext. If physical plug was used, the receiver must wire identical cables first.
Item 6 in config menu — only visible in ENCRYPT or DECRYPT mode.
| Option | What it does | Use when… |
|---|---|---|
| Keep prev settings | Resets rotors to Grundstellung. All settings kept. Clears typing display. | Sending another message with the same daily key. |
| Change settings | Opens full config menu. Rotors reset to Grundstellung before typing display opens. | Changing day sheet or rotor order mid-session. |
| Restart to default | Full factory reset: I-II-III, Ref B, Pos AAA, no plugboard. Returns to PASSTHROUGH. | Starting fresh. |
Last 8 messages in a circular buffer. Item 5 in config menu. Saved on Return key press or auto-saved when any button leaves the typing screen mid-message.
Up to 15 chars of input and output shown. When 8 messages stored, oldest is overwritten. History lost on power-off.
| Total changes | Plugboard stages active |
|---|---|
| 7 changes | No plugboard (both stages empty) |
| 8 changes | One plugboard stage active |
| 9 changes | Both plugboard stages active |
Steps 1 and 9 (green) are plugboard substitutions — present only when their stage has ≥1 pair. Physical plug pairs appear in the trace identically to manually or preset-entered pairs.
This section documents the internal mechanics of the Enigma cipher engine. Understanding the hardware analogy helps when reading PuTTY traces and diagnosing unexpected encryption output.
A rotor (German: Walze) is a disc with 26 electrical contacts on each face. Each contact on the entry face is wired to a different contact on the exit face, forming a fixed monoalphabetic substitution. In software, this is a 26-element lookup table.
Three rotors sit in a row — Left (L), Middle (M), Right (R). Every keypress steps the right rotor by one position before the electrical signal passes through. The signal travels right-to-left through all three rotors, bounces off the reflector, then travels left-to-right back. The return path uses the same wiring traversed backwards — making the cipher self-inverse.
Each table shows the substitution at rotor position A with ring offset 0. The highlighted cell (yellow) marks the output at the turnover notch position.
| IN | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OUT | E | K | M | F | L | G | D | Q | V | Z | N | T | O | W | Y | H | X | U | S | P | A | I | B | R | C | J |
| IN | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OUT | A | J | D | K | S | I | R | U | X | B | L | H | W | T | M | C | Q | G | Z | N | P | Y | F | V | O | E |
| IN | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OUT | B | D | F | H | J | L | C | P | R | T | X | V | Z | N | Y | E | I | W | G | A | K | M | U | S | Q | O |
| IN | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OUT | E | S | O | V | P | Z | J | A | Y | Q | U | I | R | H | X | L | N | F | T | G | K | D | C | M | W | B |
| IN | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OUT | V | Z | B | R | G | I | T | Y | U | P | S | D | N | H | L | X | A | W | M | J | Q | O | F | E | C | K |
| Rotor | Wiring (A→Z input) | Notch | Introduced | Notes |
|---|---|---|---|---|
| I | EKMFLGDQVZNTOWYHXUSPAIBRCJ | Q | 1930 | Wehrmacht / Luftwaffe original |
| II | AJDKSIRUXBLHWTMCQGZNPYFVOE | E | 1930 | Double-step trigger when in middle slot |
| III | BDFHJLCPRTXVZNYEIWGAKMUSQO | V | 1930 | Default right-slot rotor |
| IV | ESOVPZJAYQUIRHXLNFTGKDCMWB | J | 1938 | Expanded key space |
| V | VZBRGITYUPSDNHLXAWMJQOFECK | Z | 1938 | Notch wraps Z→A |
The reflector sits fixed at the left end of the rotor stack. It maps every letter to a unique partner and is always symmetric — if A→Y then Y→A — and no letter ever maps to itself. These two properties make the cipher self-inverse and make it impossible to encrypt a letter as itself (a weakness Bletchley Park exploited). The reflector does not step.
| IN | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OUT | E | J | M | Z | A | L | Y | X | V | B | W | F | C | R | Q | U | O | N | T | S | P | I | K | H | G | D |
| IN | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OUT | Y | R | U | H | Q | S | L | D | P | X | N | G | O | K | M | I | E | B | F | Z | C | W | V | J | A | T |
| IN | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OUT | F | V | P | J | I | A | O | Y | E | D | R | Z | X | W | G | C | T | K | U | Q | S | B | N | M | H | L |
| Term | German | What it controls |
|---|---|---|
| Ring setting | Ringstellung | Offset between the inner wiring disc and the outer alphabet ring. Shifts which contact is addressed at each rotor position. |
| Starting position | Grundstellung | The rotor position at the very start of a message. Restored automatically by the Return key and by Reset → Keep. |
The Enigma's ratchet-and-pawl mechanism differs from a simple odometer. On each keypress: the right rotor always steps; the middle steps when the right was at its turnover position; the left steps when the middle is at its own turnover — but this check happens before the middle moves, so both the middle and left step simultaneously. This creates the anomaly: the middle rotor steps on two consecutive keypresses instead of one.
| Key # | State before | What steps? | State after | Remark |
|---|---|---|---|---|
| 1 | L=A M=D R=U | R=U ≠ notch V → only R steps. | L=A M=D R=V | Normal — middle untouched. |
| 2 | L=A M=D R=V | R=V is at notch → R steps V→W and M steps D→E. | L=A M=E R=W | Normal carry. Middle now at its own notch E. |
| 3 ⚠ | L=A M=E R=W | R=W ≠ notch. But M=E is at its notch → M steps E→F AND L steps A→B. R steps W→X. | L=B M=F R=X | Double-step. Middle stepped again even though R did not trigger it. |
| 4 | L=B M=F R=X | R=X ≠ notch. M=F ≠ notch → only R steps. | L=B M=F R=Y | Normal — anomaly window closed. |
Settings: Rotors I-II-III, Reflector B, positions A-A-A, plugboard Stage 1 has pair H↔M, Stage 2 has pair C↔F.
The Enigma works on a 26-letter alphabet. Letters are represented as integers 0–25 (A=0, B=1 … Z=25). All arithmetic in the rotor substitution wraps around at 26 using the modulo operation — denoted mod 26 or % 26.
mod 26 returns the remainder after dividing by 26. Think of it as asking: after counting in a circle of 26 letters and wrapping around as many times as needed, where do you land?
| Number | ÷ 26 = | Quotient | Remainder (mod 26) | Letter |
|---|---|---|---|---|
| 34 | 34 = 1 × 26 + 8 | 1 | 8 | I |
| 46 | 46 = 1 × 26 + 20 | 1 | 20 | U |
| 26 | 26 = 1 × 26 + 0 | 1 | 0 | A |
| 48 | 48 = 1 × 26 + 22 | 1 | 22 | W |
| 38 | 38 = 1 × 26 + 12 | 1 | 12 | M |
| 50 | 50 = 1 × 26 + 24 | 1 | 24 | Y |
Every rotor substitution — forward or reverse — uses the same three-step sequence. The rotor's wiring is fixed inside the drum, but the drum has rotated, so you must convert the incoming letter into the drum's own coordinate system before looking it up, then convert the result back out.
| Term | Range | What it represents |
|---|---|---|
| input | 0–25 | The letter arriving at this rotor (A=0, B=1 … Z=25). |
| position | 0–25 | How far the drum has rotated from its home position A. The drum stepped before the signal passed. At position B (1), what the external alphabet sees as contact A is actually entering the drum at internal contact B. |
| ring | 0–25 | Ring setting offset (Ringstellung − 1). Shifts the internal wiring relative to the outer alphabet ring. With ring setting 1, offset = 0 and has no effect. |
| +26 | constant | Safety offset to prevent the value inside the parentheses from going negative before the mod. See Section 15. |
| mod 26 | result 0–25 | Wraps the total into the 0–25 alphabet range. |
| wiring[entry] | 0–25 | The fixed internal substitution at index entry — the cable soldered inside the rotor disc at the factory. |
Modulo of a negative number behaves differently in C than in mathematics. In C, (-1) % 26 evaluates to -1, not 25. The formula needs the result to be 0–25 — a negative remainder would produce an illegal array index and crash the firmware.
Adding 26 before the mod guarantees the value inside the parentheses is always ≥ 0 for any valid input (0–25), position (0–25), and ring (0–25).
| Parameter | Value | Index | Notes |
|---|---|---|---|
| Input letter | H | 7 | H is the 8th letter: A=0, B=1 … H=7 |
| Right rotor | I | — | Wiring: EKMFLGDQVZNTOWYHXUSPAIBRCJ · Notch at Q (16) |
| Middle rotor | II | — | Wiring: AJDKSIRUXBLHWTMCQGZNPYFVOE · Notch at E (4) |
| Left rotor | III | — | Wiring: BDFHJLCPRTXVZNYEIWGAKMUSQO · Notch at V (21) |
| Reflector | B | — | Wiring: YRUHQSLDPXNGOKMIEBFZCWVJAT |
| Right pos (before step) | A | 0 | Will advance to B (1) before the signal passes |
| Middle pos | A | 0 | Does not step — right rotor not at notch Q |
| Left pos | A | 0 | Does not step |
| Ring offset (all) | 0 | 0 | Ring setting 1 → offset = setting − 1 = 0. All ring terms cancel. |
| Plugboard | None | — | No Stage 1 or Stage 2 pairs |
The Enigma steps its rotors before the signal passes through. Stepping is checked and applied first; only then does the electrical signal travel through the rotors.
Three rules, applied in order:
| Rotor | Current pos | Notch at | At notch? | Verdict | New pos |
|---|---|---|---|---|---|
| Left (III) | A (0) | V (21) | 0 ≠ 21 → No | Rule 1 does not fire | A (0) — unchanged |
| Middle (II) | A (0) | E (4) | 0 ≠ 4 → No | Rule 2 does not fire | A (0) — unchanged |
| Right (I) | A (0) | Q (16) | 0 ≠ 16 → No | Rule 3 always fires → steps A→B | B (1) |
| Index | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
|---|---|---|---|---|---|---|---|
| Input | F | G | H | I | J | K | L |
| Wiring output | G | D | Q | V | Z | N | T |
| Output index | 6 | 3 | 16 | 21 | 25 | 13 | 19 |
| Index | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
|---|---|---|---|---|---|---|---|
| Input | R | S | T | U | V | W | X |
| Wiring output | G | Z | N | P | Y | F | V |
| Output index | 6 | 25 | 13 | 15 | 24 | 5 | 21 |
| Index | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
|---|---|---|---|---|---|---|---|
| Input | M | N | O | P | Q | R | S |
| Wiring output | Z | N | Y | E | I | W | G |
| Output index | 25 | 13 | 24 | 4 | 8 | 22 | 6 |
The reflector does not rotate and has no position or ring setting. It is a direct table lookup of its 13 fixed letter pairs:
| Index | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| Input | A | B | C | D | E | F | G | H |
| Reflects to | Y | R | U | H | Q | S | L | D |
| Index | 24 | 17 | 20 | 7 | 16 | 18 | 11 | 3 |
The reverse pass uses the inverse wiring table. Forward: "what does contact 15 connect to?" Reverse: "which contact connects to output 16?" The formula is identical — only the table changes.
| Index | 21 | 22 | 23 | 24 | 25 |
|---|---|---|---|---|---|
| Fwd wiring | M | U | S | Q | O |
| Fwd output idx | 12 | 20 | 18 | 16 | 14 |
| Index | 19 | 20 | 21 | 22 | 23 |
|---|---|---|---|---|---|
| Fwd wiring | N | P | Y | F | V |
| Fwd output idx | 13 | 15 | 24 | 5 | 21 |
The right rotor stepped to B (1) before the signal began. That same offset applies again here on the return pass — position B is still 1.
| Index | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
|---|---|---|---|---|---|---|---|
| Fwd wiring | N | T | O | W | Y | H | X |
| Fwd output idx | 13 | 19 | 14 | 22 | 24 | 7 | 23 |
I[13] = W = index 22. So inv_I[22] = 13. Then (13 − 1 + 0 + 26) mod 26 = 38 mod 26 = 12 = M. The −1 from position B subtracts the same offset that was added on entry.
The system intercepts the Brother SX-4000 typewriter at the hardware level. The typewriter's keyboard and its print mechanism are physically separated at their FPC connectors. The MSP432E401Y LaunchPad sits in between, reading every key pressed on the keyboard and deciding what character to send to the printer — either the same character (PASSTHROUGH), or an Enigma-transformed character (ENCRYPT/DECRYPT).
The system has three distinct hardware domains connected through the MSP432:
The diagram below shows how all hardware domains and software modules connect. Arrows show signal or data flow direction.
Every source file, what it depends on, and what depends on it.
config.h is included by every source file. It contains no executable code — only #define constants and two small lookup tables. Every GPIO pin assignment, timing constant, and letter-to-CBA mapping lives here so changing one line updates the entire system.
| Group | What it defines | Used by |
|---|---|---|
| System globals | g_ui32SysClock, g_tickMs, OperationMode enum | All files |
| UART / LCD | UART0 debug pins, UART6 LCD pins, baud rates, LCD command bytes | uart_comm.c, LCD.c |
| Control panel | BTN_MODE/SELECT/UP/DOWN/ENTER pins, LED_GREEN/RED pins, DEBOUNCE_MS | control_panel.c |
| Keyboard scan | All 16 col+row scan pins across 5 ports, NMI unlock constants for PD7 | main.c |
| MITM output | EN_PIN (PB3), KP_LED (PM0), col CBA pins (PK0-2), row CBA pins (PK3/PA4-5) | main.c |
| Lookup tables | KB_KEYS[8][8] letter map, OUTPUT_COL[26], OUTPUT_ROW[26] CBA tables | main.c |
Indexed as KB_KEYS[row][col] where row and col are 0-based indices from the active scan. Returns the letter at that matrix position or '\0' for unmapped positions.
Indexed by letter - 'A' (0=A, 25=Z). Returns the 3-bit binary index to be encoded on the CBA output pins. These values were measured directly from the typewriter's own matrix drive signals with an oscilloscope and verified against known letter positions.
| Letter | OUTPUT_COL (col CBA index) | OUTPUT_ROW (row CBA index) |
|---|---|---|
| A | 6 = CBA 110 | 6 = CBA 110 |
| B | 3 = CBA 011 | 0 = CBA 000 |
| H | 4 = CBA 100 | 4 = CBA 100 |
| Z | 6 = CBA 110 | 4 = CBA 100 |
OUTPUT_COL['Z'-'A'] to 4.main.c contains all the runtime logic. It calls functions from every other module and owns the main loop. No other file calls functions in main.c.
120 MHz PLL from 25 MHz crystal. SysTick configured for 1 ms interrupts — every module's delay_ms() depends on g_tickMs which increments here.
PB4 (green) and PB5 (red) flash 3 times. Confirms GPIO and clock are working before anything else runs.
PA0/PA1 configured as UART0 at 115200. From this point all debug output goes to PuTTY.
PP1 configured as UART6 at 9600. LCD boots and shows the idle screen.
Enigma state initialised: Reflector B, rotors I-II-III, positions A-A-A, no plugboard.
All 5 button pins and 2 LED pins configured. LCD shows idle display.
All 16 scan inputs configured (row = high-Z, col = WPU). CBA output pins go LOW. PB3 enable goes HIGH. PM0 keypress LED goes LOW.
3 second REST. The typewriter's own controller needs time to boot. During this window the MSP does not scan, preventing false detections from the typewriter's startup sequences.
| Step | What happens |
|---|---|
| get_key() | Calls scan_once() twice with 20 ms between. If the same row+col reads LOW both times, returns the debounced key character. Otherwise returns '\0'. |
| process_key() | If a key was found, determines output based on mode. Drives CBA, turns PM0 ON, waits for key release, then clears CBA and turns PM0 OFF. |
| control_panel_update() | Polls all 5 buttons, updates mode, navigates config menus, updates LCD. This runs every loop regardless of keypresses. |
| Auto-save | If the control panel leaves the typing screen mid-message, the accumulated characters are saved to history automatically. |
| Mode | Letter in | Letter out | LCD | PuTTY |
|---|---|---|---|---|
| PASSTHROUGH | key_in | same as in | Both lines show same letter | [PASS] A |
| ENCRYPT | key_in | enigma_encrypt_char_traced() | Line 2 = in, Line 3 = out | Full 7–9 step Enigma trace |
| DECRYPT | key_in (ciphertext) | enigma_encrypt_char_traced() — same function, Enigma is self-inverse | Line 2 = ciphertext, Line 3 = plaintext | Full trace |
The MSP432 owns the keyboard scan entirely. It drives the matrix itself rather than passively reading the typewriter's own scan signals. This avoids conflicts with the typewriter's analog differential sensing and gives the MSP clean digital readings.
| Signal | Pins | Config | Idle state |
|---|---|---|---|
| Row 0–3 | PE0 PE1 PE2 PE3 | Input (high-Z) between scans, output LOW during active scan | High-Z |
| Row 4 | PD7 ⚠ NMI | Same as above — requires GPIOLOCK unlock sequence at boot | High-Z |
| Row 5 | PD6 | Input (high-Z) between scans | High-Z |
| Row 6–7 | PM4 PM5 | Input (high-Z) between scans | High-Z |
| Col 0–7 | PE4 PC4 PC5 PC6 PE5 PD3 PC7 PB2 | Input + WPU — idle HIGH | HIGH |
scan_once() is called twice with a 20 ms gap. If both calls return the same letter, the key is considered stable. The wait-for-release is intentionally left to the main loop — get_key() returns immediately with the key still held so the injection can hold as long as the physical key is pressed.
PD7 (row 4) is the Non-Maskable Interrupt pin and is hardware-locked at reset. The firmware writes the unlock key (0x4C4F434B = ASCII "LOCK") to the GPIOLOCK register, sets bit 7 in GPIOCR to permit reconfiguration, then re-locks. Without this three-line sequence, every GPIOPinWrite to PD7 is silently ignored.
Once the output letter is determined (either the same as input in PASSTHROUGH, or the Enigma output in ENCRYPT/DECRYPT), it is re-encoded as a 3-bit column address and a 3-bit row address and driven onto the output pins. The CD4051BE multiplexers translate these 3-bit addresses into a physical matrix line selection, making the typewriter printer believe a specific key was pressed.
| Signal | Pin | Connector | Role |
|---|---|---|---|
| Col C (bit 2) | PK0 | J7-3 | CD4051 col mux address bit 2 (MSB) |
| Col B (bit 1) | PK1 | J7-4 | CD4051 col mux address bit 1 |
| Col A (bit 0) | PK2 | J7-5 | CD4051 col mux address bit 0 (LSB) |
| Row C (bit 2) | PK3 | J7-6 | CD4051 row mux address bit 2 (MSB) |
| Row B (bit 1) | PA4 | J7-7 | CD4051 row mux address bit 1 |
| Row A (bit 0) | PA5 | J7-8 | CD4051 row mux address bit 0 (LSB) |
| Enable | PB3 | J1-10 | CD4066 gate — HIGH permanently from boot |
| Keypress LED | PM0 | J8-4 | ON while key held, OFF on release |
The enable line PB3 is driven HIGH once at boot and never changes. The injection duration is controlled purely by how long the CBA lines are driven — the printer sees the matrix event from the moment the address pins go HIGH until they are cleared.
| Event | When |
|---|---|
| CBA pins driven, PM0 ON | Immediately when key detected (after 20 ms debounce) |
| CBA held | While scan_once() keeps finding the same key pressed |
| CBA cleared, PM0 OFF | Immediately when scan_once() returns '\0' (key released) |
The Enigma Encryption Typewriter is a real-time hardware cryptographic interceptor. A Brother SX-4000 electronic typewriter has been physically intercepted at its keyboard flat-flex cable connector (FPC1). A Texas Instruments MSP432E401Y microcontroller sits between the keyboard and the printer. Every key pressed on the typewriter keyboard is read by the MSP432, optionally transformed through a software emulation of the Wehrmacht Enigma I cipher, and re-injected into the typewriter's print mechanism as a substitute keystroke. The printer physically types the result on paper — encrypted ciphertext in ENCRYPT mode, recovered plaintext in DECRYPT mode, or the original character unchanged in PASSTHROUGH mode.
PLL from 25 MHz crystal. All delay_ms() calls depend on this.
PB4 (green) + PB5 (red) flash ×3 confirming GPIO is alive before serial output starts.
From here every event is logged to PuTTY: key presses, Enigma traces, CBA values, mode changes.
UART6 at 9600 baud on PP1. LCD shows "System Check... Please wait" for 5 s. This lets the typewriter's own controller finish its boot before the MSP starts scanning.
enigma_init() populates the EnigmaState structure. All rotor inverse tables are precomputed here.
Five buttons and two LEDs configured. LCD now shows mode and rotor positions.
16 scan pins configured (rows high-Z, columns WPU). CBA outputs go LOW. Enable line PB3 is set HIGH permanently — injection path is now live.
26 jack GPIO pins (A–Z) configured as input + WPU. Physical cable pairs are detected and applied to the Enigma state.
| Task | What happens |
|---|---|
| get_key() | Two complete 8×8 matrix sweeps 20 ms apart. Same key both times = accepted. Returns immediately without waiting for release. |
| process_key() | Mode-aware: PASSTHROUGH=inject same letter, ENCRYPT/DECRYPT=run Enigma then inject output. Space+Return always bypass Enigma. Hold injection while key held. Release=clear CBA. |
| control_panel_update() | Poll 5 buttons, update LCD, change mode, navigate config menus, auto-save messages on screen exit. |
| Component | Part number | Role in system |
|---|---|---|
| Microcontroller | MSP432E401Y | 120 MHz ARM Cortex-M4F. Runs the entire system: keyboard scan, Enigma cipher, LCD, control panel, CBA injection, UART debug. |
| Typewriter | Brother SX-4000 | Provides the 8×8 passive keyboard matrix (FPC1) and the print mechanism (FPC2). The MSP intercepts FPC1 for reading and injects into FPC2 for printing. |
| Col mux | CD4051BE ×1 | 8-channel analog mux. Receives 3-bit col CBA from PK0-PK2 and selects the corresponding column line on FPC2. |
| Row mux | CD4051BE ×1 | 8-channel analog mux. Receives 3-bit row CBA from PK3/PA4/PA5 and selects the corresponding row line on FPC2. |
| Bilateral switch | CD4066BD | Gates the connection between the selected col and row mux outputs. Enable pin (PB3) driven HIGH permanently from boot — injection path always open. |
| LCD display | NHD-0420D3Z | 20×4 character serial LCD. Driven via UART6 at 9600 baud on PP1. Displays mode, rotor positions, plaintext and ciphertext streams in real time. |
| Plugboard | 26 NC mono jacks | Physical letter-pair substitution. Normally-closed jacks: empty = LOW (NC to GND), cable inserted = HIGH (WPU). Each jack mapped to one letter A–Z. |
| Control panel | 5 buttons + 2 LEDs | MODE/SELECT/UP/DOWN/ENTER buttons navigate the configuration FSM. Green LED = ENCRYPT, Red LED = DECRYPT, both off = PASSTHROUGH. |
All 51 active GPIO pins across 15 ports. Colour groups match the system architecture.
| Pin | Signal | Connector | Function |
|---|---|---|---|
| PE4 | SCAN_COL0 | J1-2 | Keyboard matrix col 0 |
| PC4 | SCAN_COL1 | J1-3 | Keyboard matrix col 1 |
| PC5 | SCAN_COL2 | J1-4 | Keyboard matrix col 2 |
| PC6 | SCAN_COL3 | J1-5 | Keyboard matrix col 3 |
| PE5 | SCAN_COL4 | J1-6 | Keyboard matrix col 4 |
| PD3 | SCAN_COL5 | J1-7 | Keyboard matrix col 5 |
| PC7 | SCAN_COL6 | J1-8 | Keyboard matrix col 6 — Return also here at row 1 |
| PB2 | SCAN_COL7 | J1-9 | Keyboard matrix col 7 — Space also here at row 1 |
| Pin | Signal | Connector | Letters on this row |
|---|---|---|---|
| PE0 | SCAN_ROW0 | J3-23 | — (unmapped) |
| PE1 | SCAN_ROW1 | J3-24 | Return (col 6), Space (col 7) |
| PE2 | SCAN_ROW2 | J3-25 | A D G J L |
| PE3 | SCAN_ROW3 | J3-26 | B I M P R W Y |
| PD7 ⚠ | SCAN_ROW4 | J3-28 | C F H K S X Z — NMI pin, GPIOLOCK unlock required |
| PM1 | SCAN_ROW5 | J8-2 | E N O Q T U V — moved from PD6 (PD6 not scanning reliably) |
| PM4 | SCAN_ROW6 | J3-29 | — (unmapped) |
| PM5 | SCAN_ROW7 | J3-30 | — (unmapped) |
| Pin | Signal | Direction | Function |
|---|---|---|---|
| PK0 | OUT_COL_C | Output | Col CBA bit 2 (MSB) → CD4051 col mux pin C |
| PK1 | OUT_COL_B | Output | Col CBA bit 1 → CD4051 col mux pin B |
| PK2 | OUT_COL_A | Output | Col CBA bit 0 (LSB) → CD4051 col mux pin A |
| PK3 | OUT_ROW_C | Output | Row CBA bit 2 (MSB) → CD4051 row mux pin C |
| PA4 | OUT_ROW_B | Output | Row CBA bit 1 → CD4051 row mux pin B |
| PA5 | OUT_ROW_A | Output | Row CBA bit 0 (LSB) → CD4051 row mux pin A |
| PB3 | EN_PIN | Output HIGH (perm.) | CD4066 enable — HIGH from boot, never cleared |
| PM0 | KP_LED | Output | J8-4 — ON while key held, OFF on release |
| Pin | Signal | Config | Function |
|---|---|---|---|
| PB4 | LED_GREEN | Output | Green LED — ON in ENCRYPT mode, ×3 blink at boot |
| PB5 | LED_RED | Output | Red LED — ON in DECRYPT mode, ×3 blink at boot |
| PD2 | BTN_MODE | Input + WPU | Cycle mode: PASSTHROUGH → ENCRYPT → DECRYPT |
| PQ0 | BTN_SELECT | Input + WPU | Select / confirm menu item |
| PP4 | BTN_UP | Input + WPU | Increment (rotor, position, plugboard day, ring) |
| PN5 | BTN_DOWN | Input + WPU | Decrement — same parameters as UP |
| PN4 | BTN_ENTER | Input + WPU | Enter config submenus |
| PA0 | UART0_RX | UART periph. | Debug UART receive from PuTTY — 115200 8N1 |
| PA1 | UART0_TX | UART periph. | Debug UART transmit — key traces, CBA values, inject log |
| PP1 | UART6_TX | UART periph. | LCD transmit — UART6 at 9600 baud to NHD-0420D3Z |
| Letter | Pin | Port | Letter | Pin | Port | Letter | Pin | Port |
|---|---|---|---|---|---|---|---|---|
| A | PD0 | D | J | PL2 | L | S | PM7 | M |
| B | PM3 | M | K | PL1 | L | T | PP5 | P |
| C | PH2 | H | L | PL0 | L | U | PA7 | A |
| D | PH3 | H | M | PL5 | L | V | PQ2 | Q |
| E | PD1 | D | N | PL4 | L | W | PQ3 | Q |
| F | PN2 | N | O | PG0 | G | X | PQ1 | Q |
| G | PN3 | N | P | PF3 | F | Y | PM6 | M |
| H | PP2 | P | Q | PF2 | F | Z | PG1 | G |
| I | PL3 | L | R | PF1 | F |
How a single keypress travels from physical contact to printed character.
How a 3-bit index maps to physical pins. The same encoding is applied to both col (PK0-2) and row (PK3/PA4/PA5).
| Index | Binary | C (bit2) | B (bit1) | A (bit0) |
|---|---|---|---|---|
| 0 | 000 | 0 | 0 | 0 |
| 1 | 001 | 0 | 0 | 1 |
| 2 | 010 | 0 | 1 | 0 |
| 3 | 011 | 0 | 1 | 1 |
| 4 | 100 | 1 | 0 | 0 |
| 5 | 101 | 1 | 0 | 1 |
| 6 | 110 | 1 | 1 | 0 |
| 7 | 111 | 1 | 1 | 1 |
0-based indices. MSP drives row LOW during scan. Key press pulls col LOW through the switch.
| Row \ Col | 0 (PE4) | 1 (PC4) | 2 (PC5) | 3 (PC6) | 4 (PE5) | 5 (PD3) | 6 (PC7) | 7 (PB2) |
|---|---|---|---|---|---|---|---|---|
| 0 (PE0) | — | — | — | — | — | — | — | — |
| 1 (PE1) | — | — | — | — | — | — | RET | SPC |
| 2 (PE2) | — | — | L | D | J | G | A | — |
| 3 (PE3) | B | M | I | P | Y | R | W | — |
| 4 (PD7⚠) | C | X | K | S | H | F | Z | — |
| 5 (PM1) | V | N | U | O | T | E | Q | — |
| 6 (PM4) | — all unmapped — | |||||||
| 7 (PM5) | — all unmapped — | |||||||
| Letter | Col idx | Col CBA | Row idx | Row CBA | Letter | Col idx | Col CBA | Row idx | Row CBA |
|---|---|---|---|---|---|---|---|---|---|
| A | 6 | 110 | 2 | 010 | N | 1 | 001 | 5 | 101 |
| B | 0 | 000 | 3 | 011 | O | 3 | 011 | 5 | 101 |
| C | 0 | 000 | 4 | 100 | P | 3 | 011 | 3 | 011 |
| D | 3 | 011 | 2 | 010 | Q | 6 | 110 | 5 | 101 |
| E | 5 | 101 | 5 | 101 | R | 5 | 101 | 3 | 011 |
| F | 5 | 101 | 4 | 100 | S | 3 | 011 | 4 | 100 |
| G | 5 | 101 | 2 | 010 | T | 4 | 100 | 5 | 101 |
| H | 4 | 100 | 4 | 100 | U | 2 | 010 | 5 | 101 |
| I | 2 | 010 | 3 | 011 | V | 0 | 000 | 5 | 101 |
| J | 4 | 100 | 2 | 010 | W | 6 | 110 | 3 | 011 |
| K | 2 | 010 | 4 | 100 | X | 1 | 001 | 4 | 100 |
| L | 2 | 010 | 2 | 010 | Y | 4 | 100 | 3 | 011 |
| M | 1 | 001 | 3 | 011 | Z | 6 | 110 | 4 | 100 |
| Space | 7 | 111 | 1 | 001 | Return | 6 | 110 | 1 | 001 |
| File | Responsibility | Key functions |
|---|---|---|
| config.h | Single source of truth — every pin, constant, and lookup table. Included by all files. No executable code. | KEYS[][], OUTPUT_COL[], OUTPUT_ROW[] |
| main.c | System orchestrator. Startup sequence, keyboard scan, process_key(), main loop. Calls all other modules. | scan_once(), get_key(), set_cba(), process_key() |
| enigma.c/h | Complete Enigma I cipher engine. 5 rotors, 3 reflectors, dual plugboard, double-step anomaly, traced encryption. | enigma_encrypt_char_traced(), enigma_step_rotors() |
| control_panel.c/h | 6-state FSM for button navigation, mode switching, rotor config, plugboard day selection, history log, typing display. | control_panel_update(), control_panel_typing_update() |
| LCD.c/h | NHD-0420D3Z driver over UART6. Command-prefix protocol at 9600 baud. | LCD_Init(), LCD_Print(), LCD_SetCursor() |
| uart_comm.c/h | UART0 debug interface at 115200 baud. uart_putchar, uart_puts, uart_printf. | uart_init(), uart_puts(), uart_putchar() |
| plugboardhw.c/h | Scans 26 physical jack GPIO pins. NC-jack pre-filter then drive-LOW confirmation. Applies pairs to Enigma state. | plugboard_hw_init(), plugboard_hw_scan() |
| mitm.h | Legacy stub. All four functions are empty inlines. Exists only to satisfy #include in control_panel.c. | mitm_init() stub, mitm_inject_key() stub |
| system_check.c/h | Boot diagnostics. Validates reflector symmetry and no-fixed-point property at startup. | system_check_run() |
| system_msp432e401y.c | Device-specific clock and vector table configuration. Provided by TI SDK example. | SystemInit() |
The Enigma Encryption Typewriter is a real-time hardware cryptographic interceptor. A Brother SX-4000 electronic typewriter has been physically split at its keyboard connector. A Texas Instruments MSP432E401Y microcontroller sits electrically between the keyboard and the print mechanism. Every key pressed travels through the microcontroller before reaching the printer. The microcontroller can pass characters through unchanged, or encrypt them through a faithful emulation of the Wehrmacht Enigma I cipher, injecting the transformed character to the printer instead. The result is that the typewriter physically prints encrypted or decrypted text on paper.
| Mode | Input | Output | LCD line 2 | LCD line 3 |
|---|---|---|---|---|
| PASSTHROUGH | Typed letter | Same letter — identical injection | Typed letter | Same letter |
| ENCRYPT | Plaintext letter | Enigma-encrypted ciphertext letter | Plaintext | Ciphertext |
| DECRYPT | Ciphertext letter | Plaintext letter (Enigma is self-inverse) | Ciphertext | Plaintext |
| Component | Part number | Quantity | Role |
|---|---|---|---|
| Microcontroller | MSP432E401Y LaunchPad | 1 | 120 MHz ARM Cortex-M4F. Central processor. Keyboard scan, Enigma engine, injection, UI. |
| Typewriter | Brother SX-4000 | 1 | Provides keyboard (passive 8×8 matrix) and daisy-wheel print mechanism. |
| Analog multiplexer | CD4051BE | 2 | 8-channel single-ended mux. One for column selection, one for row selection on FPC2. |
| Bilateral switch | CD4066BD | 1 | Gates the injection path. Enable permanently HIGH from boot. |
| LCD display | NHD-0420D3Z-NSW-BBW | 1 | 20×4 character serial LCD. UART6 at 9600 baud on PP1. |
| Push buttons | Tactile switch | 5 | MODE / SELECT / UP / DOWN / ENTER. Control panel navigation. |
| LEDs | Standard 3mm | 3 | Green (ENCRYPT mode, PB4), Red (DECRYPT mode, PB5), Keypress indicator (PM0). |
| Plugboard jacks | 3.5mm mono NC jack | 26 | One per letter A–Z. Normally-closed to GND. Cable insertion opens NC contact. |
| FPC connectors | Matching to SX-4000 | 2 | FPC1 (keyboard side) and FPC2 (printer side) intercept connectors. |
| Resistors | 330Ω | 3 | LED current limiting. |
| Pin | Signal | Connector | Letters on this column |
|---|---|---|---|
| PE4 | col 0 | J1-2 | B C V |
| PC4 | col 1 | J1-3 | M N X |
| PC5 | col 2 | J1-4 | I K L U |
| PC6 | col 3 | J1-5 | D O P S |
| PE5 | col 4 | J1-6 | H J T Y |
| PD3 | col 5 | J1-7 | E F G R |
| PC7 | col 6 | J1-8 | A Q W Z · Return |
| PB2 | col 7 | J1-9 | Space |
| Pin | Signal | Connector | Letters / keys on this row | Note |
|---|---|---|---|---|
| PE0 | row 0 | J3-23 | — (unused) | |
| PE1 | row 1 | J3-24 | Return (col 6) · Space (col 7) | |
| PE2 | row 2 | J3-25 | A D G J L | |
| PE3 | row 3 | J3-26 | B I M P R W Y | |
| PD7 | row 4 | J3-28 | C F H K S X Z | ⚠ NMI pin — GPIOLOCK unlock required at boot |
| PM1 | row 5 | J8-2 | E N O Q T U V | Moved from PD6 (PD6 was not scanning reliably) |
| PM4 | row 6 | J3-29 | — (unused) | |
| PM5 | row 7 | J3-30 | — (unused) |
| Pin | Signal | Role | Note |
|---|---|---|---|
| PK0 | OUT_COL_C | Column CBA bit 2 (MSB) → CD4051 col mux pin C | Analog-capable — DEN auto-set by driverlib |
| PK1 | OUT_COL_B | Column CBA bit 1 → CD4051 col mux pin B | |
| PK2 | OUT_COL_A | Column CBA bit 0 (LSB) → CD4051 col mux pin A | |
| PK3 | OUT_ROW_C | Row CBA bit 2 (MSB) → CD4051 row mux pin C | Analog-capable — DEN auto-set by driverlib |
| PA4 | OUT_ROW_B | Row CBA bit 1 → CD4051 row mux pin B | |
| PA5 | OUT_ROW_A | Row CBA bit 0 (LSB) → CD4051 row mux pin A |
| Pin | Signal | Connector | Function |
|---|---|---|---|
| PB3 | EN_PIN | J1-10 | CD4066BD enable — HIGH permanently from boot. Never changes. |
| PM0 | KP_LED | J8-4 | Keypress LED — ON while CBA is driven (key held), OFF on release. |
| Pin | Signal | Connector | Function |
|---|---|---|---|
| PB4 | LED_GREEN | J2 | ON in ENCRYPT mode. Flashes ×3 at boot. |
| PB5 | LED_RED | J2 | ON in DECRYPT mode. Flashes ×3 at boot. |
| Pin | Signal | Function |
|---|---|---|
| PD2 | BTN_MODE | Cycle mode: PASSTHROUGH → ENCRYPT → DECRYPT → PASSTHROUGH |
| PQ0 | BTN_SELECT | Select / confirm current menu item |
| PP4 | BTN_UP | Increment rotor, position, plugboard day, ring setting |
| PN5 | BTN_DOWN | Decrement same parameters |
| PN4 | BTN_ENTER | Enter configuration submenus |
| Pin | Signal | Function |
|---|---|---|
| PA0 | UART0_RX | Receive from host (currently unused in firmware) |
| PA1 | UART0_TX | Transmit key trace, CBA values, INJECT ON/OFF, mode changes to PuTTY |
| Pin | Signal | Function |
|---|---|---|
| PP1 | UART6_TX | LCD transmit — command prefix 0xFE, data direct ASCII |
| Letter | Pin | Port | Letter | Pin | Port |
|---|---|---|---|---|---|
| A | PD0 | D | N | PL4 | L |
| B | PM3 | M | O | PG0 | G |
| C | PH2 | H | P | PF3 | F |
| D | PH3 | H | Q | PF2 | F |
| E | PD1 | D | R | PF1 | F |
| F | PN2 | N | S | PM7 | M |
| G | PN3 | N | T | PP5 | P |
| H | PP2 | P | U | PA7 | A |
| I | PL3 | L | V | PQ2 | Q |
| J | PL2 | L | W | PQ3 | Q |
| K | PL1 | L | X | PQ1 | Q |
| L | PL0 | L | Y | PM6 | M |
| M | PL5 | L | Z | PG1 | G |
CBA is a 3-bit binary address (C=bit2 MSB, B=bit1, A=bit0) that selects one of 8 channels on the CD4051 multiplexer. The table below shows the verified injection values for every key.
| Key | Col CBA | Col idx | Row CBA | Row idx | Col pins (PK0 PK1 PK2) | Row pins (PK3 PA4 PA5) |
|---|---|---|---|---|---|---|
| A | 110 | 6 | 010 | 2 | 1 1 0 | 0 1 0 |
| B | 000 | 0 | 011 | 3 | 0 0 0 | 0 1 1 |
| C | 000 | 0 | 100 | 4 | 0 0 0 | 1 0 0 |
| D | 011 | 3 | 010 | 2 | 0 1 1 | 0 1 0 |
| E | 101 | 5 | 101 | 5 | 1 0 1 | 1 0 1 |
| F | 101 | 5 | 100 | 4 | 1 0 1 | 1 0 0 |
| G | 101 | 5 | 010 | 2 | 1 0 1 | 0 1 0 |
| H | 100 | 4 | 100 | 4 | 1 0 0 | 1 0 0 |
| I | 010 | 2 | 011 | 3 | 0 1 0 | 0 1 1 |
| J | 100 | 4 | 010 | 2 | 1 0 0 | 0 1 0 |
| K | 010 | 2 | 100 | 4 | 0 1 0 | 1 0 0 |
| L | 010 | 2 | 010 | 2 | 0 1 0 | 0 1 0 |
| M | 001 | 1 | 011 | 3 | 0 0 1 | 0 1 1 |
| N | 001 | 1 | 101 | 5 | 0 0 1 | 1 0 1 |
| O | 011 | 3 | 101 | 5 | 0 1 1 | 1 0 1 |
| P | 011 | 3 | 011 | 3 | 0 1 1 | 0 1 1 |
| Q | 110 | 6 | 101 | 5 | 1 1 0 | 1 0 1 |
| R | 101 | 5 | 011 | 3 | 1 0 1 | 0 1 1 |
| S | 011 | 3 | 100 | 4 | 0 1 1 | 1 0 0 |
| T | 100 | 4 | 101 | 5 | 1 0 0 | 1 0 1 |
| U | 010 | 2 | 101 | 5 | 0 1 0 | 1 0 1 |
| V | 000 | 0 | 101 | 5 | 0 0 0 | 1 0 1 |
| W | 110 | 6 | 011 | 3 | 1 1 0 | 0 1 1 |
| X | 001 | 1 | 100 | 4 | 0 0 1 | 1 0 0 |
| Y | 100 | 4 | 011 | 3 | 1 0 0 | 0 1 1 |
| Z | 110 | 6 | 100 | 4 | 1 1 0 | 1 0 0 |
| Space | 111 | 7 | 001 | 1 | 1 1 1 | 0 0 1 |
| Return | 110 | 6 | 001 | 1 | 1 1 0 | 0 0 1 |
MAP_SysCtlClockFreqSet() configures the PLL from the 25 MHz crystal. SysTick fires every 1 ms and increments g_tickMs. Every delay_ms() in the system depends on this counter.
Both LEDs flash three times before any serial output. Confirms GPIO and clock are working. Visible hardware self-test.
From this point all events print to PuTTY. The first message is "Booting — 5 s system check..."
UART6 on PP1 initialises at 9600 baud. LCD displays "ENIGMA MACHINE / System Check... / Please wait". The system holds here for 5 seconds. This gives the typewriter's own controller time to finish its boot sequence and gives the operator visual confirmation that the LCD is working.
enigma_init() loads reflector UKW-B, rotors I-II-III, positions A-A-A, ring settings 1-1-1, no plugboard pairs. enigma_set_daily_settings() and enigma_set_positions() apply the day-zero configuration.
All 5 button pins and 2 LED pins configured. control_panel_update_display() draws the idle screen showing mode, rotor positions, and plugboard status. The 5-second boot screen is replaced by the operational display.
All 8 row scan pins configured as input (high-Z). All 8 column scan pins configured as input + WPU. PB3 driven HIGH — from this moment the CD4066 switch is open and the injection path is live. PM0 keypress LED driven LOW. All CBA output pins driven LOW.
All 26 jack GPIO pins configured as input + WPU. The NC-jack scan is ready to detect physical cable pairs.
PuTTY receives "Ready. Mode: PASSTHROUGH". The system enters the infinite main loop polling the keyboard every 10 ms.
get_key() calls scan_once() twice with a 20 ms gap. scan_once() drives each of the 8 rows LOW one at a time, waits 20 µs for signal settling, then reads all 8 column lines. A column that reads LOW while its row is active means a key is pressed at that intersection. KB_KEYS[row][col] returns the letter. Two consecutive matching readings confirm the press. get_key() returns without waiting for release so the key is still physically held when the result arrives.
After set_cba() drives the output pins, the firmware enters a polling loop: while(scan_once() != '\0') delay_ms(1). The CBA lines remain driven and PM0 LED stays ON for as long as the key is physically held. When the key is released, scan_once() returns null, clear_cba() zeroes all output pins, PM0 goes LOW, and [INJECT OFF] is sent to PuTTY. This ties the injection duration exactly to the physical key press duration — the typewriter's controller detects the matrix event in its next scan cycle regardless of timing.
When Return is pressed, it is injected with its fixed CBA values exactly like any other key. After the injection clears, the firmware checks if msg_len > 0. If so, the accumulated plaintext and ciphertext buffers are saved to the control panel history log with a mode tag (P, E, or D), the rotors are reset to their Grundstellung (daily starting positions), g_typing_started is cleared, and a separator is printed to PuTTY. The next key press begins a fresh message.
The typewriter keyboard's FPC1 connector is intercepted. Sixteen wires from FPC1 are routed to the MSP432 LaunchPad header pins: 8 column lines to PE4, PC4, PC5, PC6, PE5, PD3, PC7, PB2 and 8 row lines to PE0–PE3, PD7, PM1, PM4, PM5. The MSP drives each row LOW in sequence (active row-drive scan). The column lines idle HIGH through internal WPU resistors. A pressed key shorts its row to its column, pulling the column LOW and triggering detection.
FPC2 connects the typewriter's main controller board (the print side). Six CBA output lines from the MSP432 (PK0-PK3, PA4, PA5) drive the address inputs of two CD4051BE 8-channel analog multiplexers. One CD4051 selects the column line; the other selects the row line. The selected col output and selected row output are connected together through one switch of the CD4066BD bilateral switch. The CD4066 enable pin (PB3) is wired permanently HIGH. When the MSP drives a valid col/row CBA address, the two selected FPC2 lines are shorted together, simulating a key press at that matrix position. The typewriter's controller detects this in its next scan cycle and prints the corresponding character.
Five push-buttons connect each button's one leg to a GPIO pin (PD2, PQ0, PP4, PN5, PN4) and the other leg to GND. The internal WPU resistors hold the pins HIGH at rest; pressing the button pulls the pin LOW. The two LEDs connect through 330Ω resistors from PB4 and PB5 to GND. The keypress LED connects through 330Ω from PM0 to GND.
The NHD-0420D3Z LCD connects its RX pin to PP1 (UART6 TX). Power (5V or 3.3V depending on display version) and GND complete the connection. No RX from the LCD is used — the driver is transmit-only. Commands are sent with a 0xFE prefix byte followed by the command byte. Text is sent as raw ASCII bytes.
26 normally-closed 3.5mm mono jacks are each wired with their tip contact to one GPIO pin and their sleeve (ring) contact to GND. The NC contact inside each empty jack shorts tip to GND, pulling the pin LOW. When a cable is inserted, it mechanically opens the NC contact; the WPU resistor pulls the pin HIGH. When a cable connects two jacks, the drive-LOW scan detects the pair: driving one HIGH jack LOW causes the other to follow if they are connected through a cable.