Complete Reference · v1.0 · MSP432E401Y Enigma MITM Interceptor

ENIGMA MACHINE
COMPLETE REFERENCE

Control panel · Plugboard · LCD · Hardware jacks · mod 26 · Rotor formula · H → M fully traced

PlatformMSP432E401Y LaunchPad DisplayNHD-0420D3Z 20×4 LCD Plugboard26 GPIO jacks · up to 13 pairs RotorsI–V · Reflectors A/B/C Formulaentry/raw/output · mod 26 ExampleH → M fully traced (7 steps)

Contents

  1. INTERACTIVE SIMULATOR
  2. Interactive 9-step signal trace — live Enigma machine
  3. PART 1 — CONTROL PANEL & OPERATION GUIDE
  4. Hardware overview — buttons & LEDs
  5. LCD display explained
  6. Modes at a glance
  7. First power-on
  8. Configuring the machine — step by step
    • 5a — Selecting rotors
    • 5b — Setting the reflector
    • 5c — Ring position (Grundstellung)
    • 5d — Plugboard: stage menu & methods (Preset · Manual · Physical plug · Clear)
  9. Encrypting a message
  10. Decrypting a message
  11. Using Reset & Restart
  12. Viewing message history
  13. Reading the PuTTY trace
  14. Quick-reference card
  15. Enigma Machine Reference — Rotors, Reflectors & Wiring
  16. PART 2 — CIPHER ENGINE FORMULA REFERENCE
  17. What mod 26 means — the wrapping alphabet
  18. The three-part formula — every term explained
  19. Why +26 appears in the formula
  20. Machine settings for the worked example
  21. Step 0 — Rotor stepping before any substitution
  22. Step 1 — Right rotor (I) forward · pos B · ring 0
  23. Step 2 — Middle rotor (II) forward · pos A · ring 0
  24. Step 3 — Left rotor (III) forward · pos A · ring 0
  25. Step 4 — Reflector B — no formula, fixed symmetric table
  26. Step 5 — Left rotor (III) reverse · pos A · ring 0
  27. Step 6 — Middle rotor (II) reverse · pos A · ring 0
  28. Step 7 — Right rotor (I) reverse · pos B · ring 0
  29. Complete signal chain — H → M

9-step signal trace — live Enigma machine

Machine configuration
Left rotor — R1
A
position
window
Rotor
Pos
Ring
Middle rotor — R2
A
position
window
Rotor
Pos
Ring
Right rotor — R3
A
position
window
Rotor
Pos
Ring
Reflector + plugboards
Reflector (UKW)
Plugboard stage 1 (e.g. AB CD)
Plugboard stage 2
Encode a letter — 9-step animated trace
Press key
Encode full message
Encrypted output
A
⟶
Z
Left: A
Mid: A
Right: A
Part 1 of 2
Control Panel & Operation Guide
NHD-0420D3Z LCD · 5 push-buttons · 26 hardware jacks (A–Z) · RS-232 · MITM Board · PuTTY terminal

Hardware overview — buttons & LEDs

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.

Push-buttons

MODEPD2 — cycle operating mode
SELECTPQ0 — cycle rotor slot / confirm
UPPP4 — increment / scroll up
DOWNPN5 — decrement / scroll down
ENTERPN4 — open config / confirm / back

Status LEDs

GREENPB4 — ENCRYPT mode active
REDPB5 — DECRYPT mode active
BOTH OFFPASSTHROUGH mode
BOTH FLASHBoot blink (×3 on startup)
ButtonIn normal / typing screenIn any menu
MODECycle PASSTHROUGH → ENCRYPT → DECRYPTSame — always cycles mode
SELECTCycle selected rotor slot (R → M → L)Confirm highlighted item / enter sub-menu
UPIncrement selected rotor positionMove cursor up / change value forward
DOWNDecrement selected rotor positionMove cursor down / change value backward
ENTEROpen config menu (all modes)Go back one level / cancel without applying
Debounce: 200 ms lockout after each press. Hold-down does not repeat.

J5 connector pin layout — buttons & LEDs

J5 PinSignalGPIODirectionActive stateFunction
J5 pin 2BTN_MODEPD2InputLOW (WPU)Cycle operating mode
J5 pin 4LCD_TXPP1OutputUART TXRS-232 to NHD-0420D3Z (9 600 baud)
J5 pin 7BTN_SELECTPQ0InputLOW (WPU)Confirm / cycle rotor slot
J5 pin 8BTN_UPPP4InputLOW (WPU)Increment / scroll up
J5 pin 9BTN_DOWNPN5InputLOW (WPU)Decrement / scroll down
J5 pin 10BTN_ENTERPN4InputLOW (WPU)Open config / go back
J5 (PB4)LED_GREENPB4OutputHIGH = onENCRYPT mode indicator
J5 (PB5)LED_REDPB5OutputHIGH = onDECRYPT mode indicator
WPU = Weak Pull-Up. Button pins are configured as GPIO inputs with internal pull-ups enabled. Pressing a button shorts the pin to GND, pulling it LOW. The firmware detects a falling edge from HIGH to LOW as a valid press.

LCD display explained

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 connector pin layout

LCD PinSignalLaunchPadGPIO / PeripheralNotes
LCD RXSerial data inJ5 pin 4PP1 — UART6 TXRS-232, single wire, 9 600 baud 8N1
LCD VDD+5 V powerJ5 VCC rail—LCD requires 5 V
LCD GNDGroundJ5 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 peripheralTX pinBaudFormatBoot delay
SYSCTL_PERIPH_UART6PP19 6008N1500 ms after power-on
No LCD output? Verify R1 and R2 on the back of the NHD-0420D3Z PCB are both open. If either is shorted the display will be in I²C or SPI mode and will ignore RS-232 data. Confirm TX wire connects PP1 → LCD RX, and that the display has 5 V power.

LCD command reference

Command bytePrefixFunction
0x510xFEClear screen and reset cursor to home
0x45 + addr0xFESet cursor to DDRAM address
0x410xFEDisplay on
0x53 + level0xFESet backlight brightness (0–8)
LCD lineDDRAM start addressColumns
Line 10x000–19
Line 20x400–19
Line 30x140–19
Line 40x540–19
Inter-byte delay: The firmware inserts a 2 ms delay between consecutive bytes. The clear command (0x51) requires an additional 8 ms before the next command is sent.

Normal / idle screen

ENIGMA MACHINE Mode: PASSTHROUGH L:I M:II R:[III] A B >C< PB:0+0
Normal display — PASSTHROUGH
Four lines always visible

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.

Typing / encryption screen

ENC A A F HELLO XYZWV I-II-III PB:5+3
Typing — ENCRYPT — 5 characters
Appears on first keystroke in ENC/DEC

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.

Modes at a glance

PASSTHROUGH→ ENCRYPT→ DECRYPT→ PASSTHROUGH
ModeLEDMITM gateWhat happens when you type
PASSTHROUGHBoth offSW_PASS HIGH — keyboard → typewriter directCharacters pass through unchanged.
ENCRYPTGreen onSW_PASS LOW — intercept activeMSP432 scans, encrypts, injects output on FPC2. Typewriter prints ciphertext.
DECRYPTRed onSW_PASS LOW — intercept activeSame path — Enigma is self-inverse. Type ciphertext, typewriter prints plaintext.
Auto-save on mode change: Mid-message characters are saved to history automatically before the mode switches.

First power-on

1
Both LEDs flash three times

Boot blink — confirms the MCU started and GPIO is working.

2
MITM initialises to passthrough

SW_PASS (U7) HIGH, OE_245 HIGH, INH_4051 HIGH. Typewriter works normally.

3
LCD warms up and normal display appears

Default: PASSTHROUGH · Rotors I-II-III · Reflector B · Positions AAA · No plugboard.

ENIGMA MACHINE Mode: PASSTHROUGH L:I M:II R:[III] A B >C< PB:0+0
Expected LCD after boot
4
PuTTY shows the startup banner

Serial · COM port · 115 200 baud · 8N1. Should see banner then "Ready."

No LCD? Check RS-232 wiring on PP1. Verify R1=open, R2=open on back of display PCB. Verify 9 600 baud and 5 V power.

Configuring the machine — step by step

Press ENTER from any screen to open config. Press ENTER again inside any sub-menu to go back one level without applying changes.

5a — Selecting rotors

Select RIGHT Rotor I II III IV V Rotor: III UP/DW=chg SEL=next
Right rotor (opens first)
ENTER → Rotors → SELECT. Starts with Right.

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

5b — Setting the reflector

Select Reflector A B C Reflector: B UP/DW=chg SEL=apply
Reflector B — historical default
Config → Reflector → SELECT

UPDOWN pick A/B/C. SELECT applies. PuTTY: Reflector: B

5c — Ring position (Grundstellung)

RIGHT Rotor Start A B C ... Z Position: >A< UP/DW=chg SEL=next
Ring position — right rotor
Config → Ring Pos. Right → Mid → Left.

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

Grundstellung: Both sender and receiver must set identical ring positions before a session begins.

5d — Plugboard

Two independent stages. Stage 1 substitutes before the rotors. Stage 2 substitutes after. Each stage holds 0–13 pairs.

PLUGBOARD SETUP > Stage 1 (In): 0 Stage 2 (Out): 0 ENTER=back config
Stage selection menu
Config → Plugboard. Toggle Stage 1/2 with UP/DOWN, SELECT to enter.

Number beside each stage = active pairs. ENTER returns to config.

Stage 1 (In) Method > Preset (Day sheet) Manual entry Physical plug
Method menu (scroll down for Clear)
Four methods available

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.

Method A — Preset (day sheet)

Stg1 Day:1 BF SD AY HG OU QC W I RL XP ZK UP/DW=day SEL=apply
Day 1 shown across lines 2–3
UP/DOWN scrolls 31 days. SELECT applies.

PuTTY confirms pairs and count. ENTER cancels.

Method B — Manual entry

Stg1 Pair 1/5 First letter: > B < UP/DW=chg SEL=next
First letter — used letters auto-skipped
Set pair count (0–13) → enter each pair: first letter, then second.

Used letters are skipped automatically. After all pairs, auto-applied. PuTTY: Stage1: BF SD ... (05 pairs)

Method C — Physical plug (hardware jacks)

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.

§ Physical reality — how cables work

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.

// Each cable = two jacks that always move together
A
B
Cable 1: A ↔ B are PAIRED — pulling removes both simultaneously
C
—
Cable 2: C is WAITING — other end not inserted yet
D
E
Cable 3: D ↔ E are PAIRED — independent of Cables 1 and 2
The 5 state transitions — every possible event
#EventBeforeAfter
T1Insert plug — no waiting pair existsBoard empty or all pairs PAIREDNew pair opens. Jack = Slot 1. WAITING.
T2Insert plug — a waiting pair existsPair N has Slot 1, no Slot 2Jack fills Slot 2 of oldest waiting pair. PAIRED.
T3Remove Slot 2 from a PAIRED pairPair N: Slot1 ↔ Slot2 PAIREDSlot 2 cleared. Slot 1 unchanged. Pair → WAITING.
T4Remove Slot 1 from a PAIRED pairPair N: Slot1 ↔ Slot2 PAIREDSlot 2 promoted to Slot 1. Pair → WAITING.
T5Remove only jack from a WAITING pairPair N: Slot 1 onlyPair dissolved. Pairs below shift up.
Same-window dual removal (cable pulled completely)

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 endsA→Z order firesResult
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 ✓
First-come, first-served pairing

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.

Step-by-step UART trace — A, B, C example
UART0 · 115200 8N1 — 3-jack walkthrough
--- Insert one end of Cable 1 into A ---
Inserted: A
[WAITING] Jack A inserted as Pair 1 Slot 1 — plug in a partner jack
P1: [A] WAITING for partner...

--- Insert one end of Cable 2 into C ---
Inserted: A C
[WAITING] Jack C inserted as Pair 2 Slot 1 — plug in a partner jack
P1: [A] WAITING for partner...
P2: [C] WAITING for partner...

--- Insert other end of Cable 1 into B (A waited longest) ---
Inserted: A B C
[PAIRED] Jack A <--> Jack B (Pair 1)
P1: [A] <--> [B] PAIRED
P2: [C] WAITING for partner...

--- Pull Cable 1 completely out (A and B both go LOW) ---
Inserted: C
[UNPLUGGED] Jack A removed from Pair 1 → Jack B promoted to Slot 1
[UNPLUGGED] Jack B removed — Pair 1 dissolved, pairs re-numbered
P1: [C] WAITING for partner...

C kept its spot — its cable was never touched.

Using the physical plug screen on the LCD

Stage 1 (In) Method Manual entry Physical plug > Clear (0 pairs)
Scroll down to reach Physical plug
Step 1 — select Physical plug

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.

Stg1 Phys PB:0pr SEL=apply ENT=back
No cables yet — board empty
Step 2 — scan screen appears

Line 1 shows stage and pair count. Lines 2–3 blank. Firmware rescans every ~20 ms loop tick.

Stg1 Phys PB:7pr AB CD EF GH IJ KL MN OP SEL=apply ENT=back
Seven pairs — verify before applying
Step 3 — plug cables, Step 4 — verify and press SELECT

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)

Drive-low scan: For each jack index 0–25, the firmware briefly reconfigures that GPIO as an output driven LOW, reads all other pins (still input+WPU). Any pin reading LOW is shorted via cable. After reading, pin is immediately restored to input+WPU. Only pairs where the lower-index jack is the driver are recorded — each cable counted exactly once.
§ Interactive simulator — click to insert / remove plugs

Green = WAITING for partner.  Red = PAIRED.  Small number = pair index. Simulates all 5 transitions exactly as the firmware does.

Physical Plugboard A–Z · Up to 13 Pairs
0 pairs active
No plugs inserted — click any letter above
Click a letter to insert a plug
§ Jack GPIO assignments — all 26 letters

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.

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

Connector pin layout

J2 — Outer A–H
11GND — skip—
12PM3B
13PH2C
14PH3D
15RST — skip—
16PD1E
17PD0A
18PN2F
19PN3G
20PP2H
J4 — Inner I–R
31PL3I
32PL2J
33PL1K
34PL0L
35PL5M
36PL4N
37PG0O
38PF3P
39PF2Q
40PF1R
J6 — Outer S–Y
1GND — skip—
2PM7S
3PP5T
4PA7U
5RST — skip—
6PQ2V
7PQ3W
8PQ1X
9PM6Y
J8 — Inner Z
1PG1Z
2–10PK4–PK7, PM0–PM2, PH0–PH1 unused—
Never use RST or GND pins: J2-11 (GND), J2-15 (RST), J6-1 (GND), J6-5 (RST) are power and reset lines.

Hardware wiring guide

Method D — Clear

Stage 1 (In) Method Manual entry Physical plug > Clear (0 pairs)
Scroll to Clear (bottom of method menu)
Scroll past Physical plug and press SELECT

All pairs in the selected stage are immediately removed. PuTTY confirms: Stage cleared

Encrypting a message

ENIGMA MACHINE Mode: ENCRYPT L:I M:II R:[III] A B >C< PB:5+3
Ready to encrypt — green LED on
1 — Switch to ENCRYPT

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.

ENC A A B H X I-II-III PB:5+3
First character — H encrypted to X
2 — Type on the typewriter keyboard

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.

ENIGMA MACHINE Mode: ENCRYPT L:I M:II R:[III] A B >C< PB:5+3
After Return — rotors reset, ready for next
3 — Press Return to end the message

Rotors reset to Grundstellung. Message saved to history. LCD returns to normal. PuTTY: --- message end (rotors reset) ---

Important: Every new message must start from the same Grundstellung. Always press Return between messages.

Decrypting a message

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.

DEC A A B XYZWV HELLO I-II-III PB:5+3
DECRYPT — ciphertext → plaintext below
Switch to DECRYPT (red LED). Type ciphertext on typewriter keyboard.

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.

Using Reset & Restart

Item 6 in config menu — only visible in ENCRYPT or DECRYPT mode.

-- RESET MENU -- > Keep prev settings Change settings Restart to default
Reset menu — UP/DOWN, SELECT to confirm
ENTER → scroll to Reset/Restart → SELECT
OptionWhat it doesUse when…
Keep prev settingsResets rotors to Grundstellung. All settings kept. Clears typing display.Sending another message with the same daily key.
Change settingsOpens full config menu. Rotors reset to Grundstellung before typing display opens.Changing day sheet or rotor order mid-session.
Restart to defaultFull factory reset: I-II-III, Ref B, Pos AAA, no plugboard. Returns to PASSTHROUGH.Starting fresh.

Viewing message history

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.

[1/3] ENCRYPT IN: HELLO OUT: XYZWV UP/DW=prv/nxt ENT=ok
History — newest first
DOWN = older, UP = newer. ENTER or SELECT = back to config.

Up to 15 chars of input and output shown. When 8 messages stored, oldest is overwritten. History lost on power-off.

Reading the PuTTY trace

Total changesPlugboard stages active
7 changesNo plugboard (both stages empty)
8 changesOne plugboard stage active
9 changesBoth plugboard stages active
9-change trace — H encrypted to F
[ENC] H => F (9 changes)
1. PB-stage1 : H -> M
  2. R-right fwd: M -> Z
  3. R-mid fwd: Z -> Q
  4. R-left fwd: Q -> P
  5. Reflect : P -> W
  6. R-left rev: W -> K
  7. R-mid rev: K -> A
  8. R-right rev: A -> C
9. PB-stage2 : C -> F

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.

Quick-reference card

Button map — normal screen
MODECycle PASS→ENC→DEC
SELECTCycle rotor slot R→M→L
UPIncrement rotor position
DOWNDecrement rotor position
ENTEROpen config menu
Button map — inside any menu
UP / DOWNMove cursor / change value
SELECTConfirm / enter item
ENTERGo back one level / cancel
Config menu items
1 · RotorsI–V per slot
2 · ReflectorA / B / C
3 · PlugboardStage 1 & 2 pairs
4 · Ring PosGrundstellung
5 · HistoryLast 8 messages
6 · Reset/RestartENC/DEC only
Physical plug transitions
T1Insert → no wait → WAITING
T2Insert → wait exists → PAIRED
T3Remove Slot2 → back to WAITING
T4Remove Slot1 → Slot2 promoted
T5Remove only jack → dissolved
LED states & PuTTY changes
Green ONENCRYPT mode
Red ONDECRYPT mode
Both OFFPASSTHROUGH
7 changesNo plugboard
8 / 9 changesOne / both PB stages
Plugboard methods (4 items)
Preset31 day sheets
ManualEnter pairs on-screen
Physical plugRead hardware jacks live
ClearScroll down to reach
Full reset: ENTER → Reset/Restart (item 6, ENC/DEC only) → SELECT → Restart to default → SELECT. Returns to factory state: I-II-III · Ref B · Pos AAA · No plugboard · PASSTHROUGH.
Physical plug quick steps: ENTER → Plugboard → Stage 1 or 2 → SELECT → DOWN to Physical plug → SELECT → insert cables → verify pairs on LCD → SELECT to apply.

Enigma Machine Reference — Rotors, Reflectors & Wiring

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.

12a — What is a rotor?

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.

Self-inverse property: If pressing A produces X in ENCRYPT mode, then pressing X produces A with the same settings. The firmware uses the exact same enigma_encrypt_char() function for both directions.

12b — Rotor wiring tables (I through V)

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.

ROTOR I
Turnover notch: Q  ·  Introduced 1930
INABCDEFGHIJKLMNOPQRSTUVWXYZ
OUTEKMFLGDQVZNTOWYHXUSPAIBRCJ
ROTOR II
Turnover notch: E  ·  Middle rotor in I-II-III config — causes double-step anomaly  ·  Introduced 1930
INABCDEFGHIJKLMNOPQRSTUVWXYZ
OUTAJDKSIRUXBLHWTMCQGZNPYFVOE
ROTOR III
Turnover notch: V  ·  Most common right-slot rotor  ·  Introduced 1930
INABCDEFGHIJKLMNOPQRSTUVWXYZ
OUTBDFHJLCPRTXVZNYEIWGAKMUSQO
ROTOR IV
Turnover notch: J  ·  Added for extended key space  ·  Introduced 1938
INABCDEFGHIJKLMNOPQRSTUVWXYZ
OUTESOVPZJAYQUIRHXLNFTGKDCMWB
ROTOR V
Turnover notch: Z  ·  Wraps A→Z  ·  Introduced 1938
INABCDEFGHIJKLMNOPQRSTUVWXYZ
OUTVZBRGITYUPSDNHLXAWMJQOFECK

12c — Rotor summary table

RotorWiring (A→Z input)NotchIntroducedNotes
IEKMFLGDQVZNTOWYHXUSPAIBRCJQ1930Wehrmacht / Luftwaffe original
IIAJDKSIRUXBLHWTMCQGZNPYFVOEE1930Double-step trigger when in middle slot
IIIBDFHJLCPRTXVZNYEIWGAKMUSQOV1930Default right-slot rotor
IVESOVPZJAYQUIRHXLNFTGKDCMWBJ1938Expanded key space
VVZBRGITYUPSDNHLXAWMJQOFECKZ1938Notch wraps Z→A

12d — Reflectors (Umkehrwalze)

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.

REFLECTOR A
Original Wehrmacht reflector
INABCDEFGHIJKLMNOPQRSTUVWXYZ
OUTEJMZALYXVBWFCRQUONTSPIKHGD
REFLECTOR B  ★ Default (boot setting)
Standard Wehrmacht / Luftwaffe reflector — most common historically
INABCDEFGHIJKLMNOPQRSTUVWXYZ
OUTYRUHQSLDPXNGOKMIEBFZCWVJAT
REFLECTOR C
Later variant — used from 1941 onwards in some units
INABCDEFGHIJKLMNOPQRSTUVWXYZ
OUTFVPJIAOYEDRZXWGCTKUQSBNMHL
Symmetry check: Pick any letter in Reflector B and trace back. A→Y and Y→A. D→H and H→D. Every pair is symmetric and no letter maps to itself.

12e — Ring position (Ringstellung / Grundstellung)

TermGermanWhat it controls
Ring settingRingstellungOffset between the inner wiring disc and the outer alphabet ring. Shifts which contact is addressed at each rotor position.
Starting positionGrundstellungThe rotor position at the very start of a message. Restored automatically by the Return key and by Reset → Keep.
adjusted_in = (input + ring_offset) mod 26
raw_out = wiring[adjusted_in]
actual_out = (raw_out − ring_offset + 26) mod 26
Critical: Both sender and receiver must use identical Ring Pos settings. Even a one-letter difference in Grundstellung produces completely different ciphertext from the very first character.

12f — The double-step anomaly

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.

Worked example — Rotors I-II-III, Reflector B

Key #State beforeWhat steps?State afterRemark
1L=A M=D R=UR=U ≠ notch V → only R steps.L=A M=D R=VNormal — middle untouched.
2L=A M=D R=VR=V is at notch → R steps V→W and M steps D→E.L=A M=E R=WNormal carry. Middle now at its own notch E.
3 ⚠L=A M=E R=WR=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=XDouble-step. Middle stepped again even though R did not trigger it.
4L=B M=F R=XR=X ≠ notch. M=F ≠ notch → only R steps.L=B M=F R=YNormal — anomaly window closed.
Why it matters: The middle rotor visits its notch position for only one keypress instead of two, and the left rotor advances one keystroke earlier than a naive model predicts. The firmware in enigma.c implements the correct three-pawl stepping sequence.

12g — Full signal path — example H → F

Settings: Rotors I-II-III, Reflector B, positions A-A-A, plugboard Stage 1 has pair H↔M, Stage 2 has pair C↔F.

1.H→MPlugboard Stage 1 (H↔M)
2.M→ZRotor III forward
3.Z→QRotor II forward
4.Q→PRotor I forward
5.P→WReflector B (P↔W)
6.W→KRotor I reverse
7.K→ARotor II reverse
8.A→CRotor III reverse
9.C→FPlugboard Stage 2 (C↔F)
Result: H → F  ·  9 steps in PuTTY trace (2 plugboard + 3 forward + 1 reflect + 3 reverse).
Part 2 of 2
Cipher Engine Formula Reference
mod 26 arithmetic · entry / raw / output formula · complete H → M trace · 7 steps fully calculated

What mod 26 means — the wrapping alphabet

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?

34 mod 26
8
= I
26 mod 26
0
= A (wraps)
46 mod 26
20
= U
38 mod 26
12
= M
50 mod 26
24
= Y
48 mod 26
22
= W
30 mod 26
4
= E
42 mod 26
16
= Q
How to compute mod 26 by hand: Divide the number by 26 and take only the remainder. 34 ÷ 26 = 1 remainder 8. 46 ÷ 26 = 1 remainder 20. If the number is already 0–25 it is unchanged: 15 mod 26 = 15.
Number÷ 26 =QuotientRemainder (mod 26)Letter
3434 = 1 × 26 + 818I
4646 = 1 × 26 + 20120U
2626 = 1 × 26 + 010A
4848 = 1 × 26 + 22122W
3838 = 1 × 26 + 12112M
5050 = 1 × 26 + 24124Y

The three-part formula — every term explained

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.

Step A — shift input INTO the drum's frame of reference
entry= (input + position − ring + 26) mod 26
Step B — look up the fixed internal wiring
raw= wiring[entry]    ← index into the 26-element table
Step C — shift result BACK to the fixed alphabet frame
output= (raw − position + ring + 26) mod 26

What each term means physically

TermRangeWhat it represents
input0–25The letter arriving at this rotor (A=0, B=1 … Z=25).
position0–25How 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.
ring0–25Ring setting offset (Ringstellung − 1). Shifts the internal wiring relative to the outer alphabet ring. With ring setting 1, offset = 0 and has no effect.
+26constantSafety offset to prevent the value inside the parentheses from going negative before the mod. See Section 15.
mod 26result 0–25Wraps the total into the 0–25 alphabet range.
wiring[entry]0–25The fixed internal substitution at index entry — the cable soldered inside the rotor disc at the factory.
Key insight: If the rotor were at position A (0) with no ring offset, both the +position and −position vanish — the formula reduces to just the wiring lookup itself. The offsets only matter when the drum has rotated away from home.

Why +26 appears in the formula

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).

Worst case — minimum possible value before +26
entry= (0 + 0 − 25 + 26) mod 26 = 1 mod 26 = 1 ✓
Without +26 — negative result crashes the firmware
entry= (0 + 0 − 25) mod 26 = −25 mod 26 = −25 ✗ (invalid index)
The +26 never changes the result. Adding 26 to a number before taking mod 26 is mathematically identical to not adding it — 26 mod 26 = 0, so the extra 26 vanishes into the remainder. Its sole purpose is preventing a negative value from reaching the wiring table index in C.

Machine settings for the worked example

ParameterValueIndexNotes
Input letterH7H is the 8th letter: A=0, B=1 … H=7
Right rotorI—Wiring: EKMFLGDQVZNTOWYHXUSPAIBRCJ · Notch at Q (16)
Middle rotorII—Wiring: AJDKSIRUXBLHWTMCQGZNPYFVOE · Notch at E (4)
Left rotorIII—Wiring: BDFHJLCPRTXVZNYEIWGAKMUSQO · Notch at V (21)
ReflectorB—Wiring: YRUHQSLDPXNGOKMIEBFZCWVJAT
Right pos (before step)A0Will advance to B (1) before the signal passes
Middle posA0Does not step — right rotor not at notch Q
Left posA0Does not step
Ring offset (all)00Ring setting 1 → offset = setting − 1 = 0. All ring terms cancel.
PlugboardNone—No Stage 1 or Stage 2 pairs

Step 0 — Rotor stepping before any substitution

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.

0
Stepping logic — applied before signal travels

Three rules, applied in order:

Rule 1IF middle at notch → left steps AND middle steps
Rule 2ELSE IF right at notch → middle steps
Rule 3ALWAYS → right steps
RotorCurrent posNotch atAt notch?VerdictNew pos
Left (III)A (0)V (21)0 ≠ 21 → NoRule 1 does not fireA (0) — unchanged
Middle (II)A (0)E (4)0 ≠ 4 → NoRule 2 does not fireA (0) — unchanged
Right (I)A (0)Q (16)0 ≠ 16 → NoRule 3 always fires → steps A→BB (1)
Result after stepping: Left = A (0) · Middle = A (0) · Right = B (1). Only the right rotor moved. This position B is what all Step 1 formula substitutions use.

Step 1 — Right rotor (I) forward · pos = B (1) · ring = 0

1
Rotor I · Forward pass · Right slot
input H (7) · position B (1) · ring offset 0
ROTOR I FWD
Entry formula — shift INTO drum frame
formulaentry = (input + pos − ring + 26) mod 26
substitute= (7 + 1 − 0 + 26) mod 26
sum= 34
mod 2634 = 1 × 26 + 8
entry = 8 → letter I
Output formula — shift BACK to alphabet
rawRotor I[8] = V = index 21
substitute= (21 − 1 + 0 + 26) mod 26
sum= 46
mod 2646 = 1 × 26 + 20
output = 20 → letter U

Wiring lookup — Rotor I at entry index 8

Index567891011
InputFGHIJKL
Wiring outputGDQVZNT
Output index631621251319
H
→
U
H (7) → entry 8 (I) → wiring: V (21) → output 20 (U)
Position B(1) shifted entry +1 and was compensated −1 on exit.

Step 2 — Middle rotor (II) forward · pos = A (0) · ring = 0

2
Rotor II · Forward pass · Middle slot
input U (20) · position A (0) · ring offset 0
ROTOR II FWD
Position A (0) — note the simplification: When position = 0 and ring = 0, both terms cancel. entry = input mod 26 = input. The frame-shift has no effect.
Entry formula
substitute= (20 + 0 − 0 + 26) mod 26
sum= 46
mod 2646 = 1 × 26 + 20
entry = 20 → letter U
Output formula
rawRotor II[20] = P = index 15
substitute= (15 − 0 + 0 + 26) mod 26
sum= 41
mod 2641 = 1 × 26 + 15
output = 15 → letter P

Wiring lookup — Rotor II at entry index 20

Index17181920212223
InputRSTUVWX
Wiring outputGZNPYFV
Output index625131524521
U
→
P
U (20) → entry 20 (U) → wiring: P (15) → output 15 (P)
Position 0 means no frame shift — entry equals input directly.

Step 3 — Left rotor (III) forward · pos = A (0) · ring = 0

3
Rotor III · Forward pass · Left slot
input P (15) · position A (0) · ring offset 0
ROTOR III FWD
Entry formula
substitute= (15 + 0 − 0 + 26) mod 26
sum= 41
mod 2641 = 1 × 26 + 15
entry = 15 → letter P
Output formula
rawRotor III[15] = E = index 4
substitute= (4 − 0 + 0 + 26) mod 26
sum= 30
mod 2630 = 1 × 26 + 4
output = 4 → letter E

Wiring lookup — Rotor III at entry index 15

Index12131415161718
InputMNOPQRS
Wiring outputZNYEIWG
Output index25132448226
P
→
E
P (15) → entry 15 (P) → wiring: E (4) → output 4 (E)
Three forward rotors complete. Signal now hits the reflector.

Step 4 — Reflector B — no formula, fixed symmetric table

4
Reflector B · Fixed wiring · No position · No ring
input E (4)
REFLECTOR B

The reflector does not rotate and has no position or ring setting. It is a direct table lookup of its 13 fixed letter pairs:

output= reflector_B[input]   ← simple direct lookup, no offset math
= reflector_B[4] = Q = index 16

Reflector B wiring at index 4

Index01234567
InputABCDEFGH
Reflects toYRUHQSLD
Index24172071618113
Symmetry check: E→Q and Q→E. Try it: reflector_B[16] = E = index 4. This symmetric property is what makes Enigma self-inverse.
E
→
Q
E (4) reflects to Q (16) in Reflector B.
Signal now reverses direction and travels back through all three rotors.

Step 5 — Left rotor (III) reverse · pos = A (0) · ring = 0

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.

Building the inverse: For every i, if wiring[i]=j then inverse[j]=i. Rotor III wiring: at index 24 the output is Q (index 16). So inv_III[16] = 24.
5
Rotor III · Reverse pass · Left slot · using inverse wiring
input Q (16) · position A (0) · ring offset 0
ROTOR III REV
Entry formula — same as forward
substitute= (16 + 0 − 0 + 26) mod 26
sum= 42
mod 2642 = 1 × 26 + 16
entry = 16 → letter Q
Output formula — using inverse table
rawinv_III[16] = 24 (Q is at III[24])
substitute= (24 − 0 + 0 + 26) mod 26
sum= 50
mod 2650 = 1 × 26 + 24
output = 24 → letter Y

Inverse lookup — which position in III wiring produces output Q (16)?

Index2122232425
Fwd wiringMUSQO
Fwd output idx1220181614
Q
→
Y
Q (16) → entry 16 (Q) → inv_III[16]=24 (Y) → output 24 (Y)

Step 6 — Middle rotor (II) reverse · pos = A (0) · ring = 0

6
Rotor II · Reverse pass · Middle slot · using inverse wiring
input Y (24) · position A (0) · ring offset 0
ROTOR II REV
Entry formula
substitute= (24 + 0 − 0 + 26) mod 26
sum= 50
mod 2650 = 1 × 26 + 24
entry = 24 → letter Y
Output formula — using inverse table
rawinv_II[24] = 21 (Y is at II[21])
substitute= (21 − 0 + 0 + 26) mod 26
sum= 47
mod 2647 = 1 × 26 + 21
output = 21 → letter V

Inverse lookup — which position in II wiring produces output Y (24)?

Index1920212223
Fwd wiringNPYFV
Fwd output idx131524521
Y
→
V
Y (24) → entry 24 (Y) → inv_II[24]=21 (V) → output 21 (V)

Step 7 — Right rotor (I) reverse · pos = B (1) · ring = 0

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.

7
Rotor I · Reverse pass · Right slot · using inverse wiring
input V (21) · position B (1) · ring offset 0
ROTOR I REV
Entry formula — position B (1) is active again
formulaentry = (input + pos − ring + 26) mod 26
substitute= (21 + 1 − 0 + 26) mod 26
sum= 48
mod 2648 = 1 × 26 + 22
entry = 22 → letter W
Output formula — inverse wiring, −pos compensates
rawinv_I[22] = 13 (W is at I[13])
substitute= (13 − 1 + 0 + 26) mod 26
sum= 38
mod 2638 = 1 × 26 + 12
output = 12 → letter M

Inverse lookup — which position in I wiring produces output W (22)?

Index10111213141516
Fwd wiringNTOWYHX
Fwd output idx1319142224723

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.

V
→
M
V (21) → entry 22 (W) → inv_I[22]=13 → output (13−1+26)%26 = 12 (M)
Why position B (1) appears in both Step 1 and Step 7: The right rotor stepped to B before the signal started. It stays at B for the entire journey — both the forward pass and the return pass. The rotor does not step again until the next keypress.

Complete signal chain — H → M

Full 7-step trace · No plugboard · Rotors III-II-I · Ref B · Pos AAB
Settings: Rotors III(L) II(M) I(R) · Reflector B · Pos A-A-A · Ring 0-0-0 · No plugboard
Input: H = index 7

── Step 0: Rotor stepping ─────────────────────────────────
Right (I): A(0) → B(1) [always steps]
Middle (II): A(0) → A(0) [right was not at notch Q]
Left (III): A(0) → A(0) [middle was not at notch E]
Positions now: L=A(0) M=A(0) R=B(1)

── Step 1: Right rotor (I) forward · pos=B(1) ────────────
entry = (7 + 1 − 0 + 26) mod 26 = 34 mod 26 = 8 (I)
raw = I[8] = V = 21
output = (21 − 1 + 0 + 26) mod 26 = 46 mod 26 = 20 (U)

── Step 2: Middle rotor (II) forward · pos=A(0) ──────────
entry = (20 + 0 − 0 + 26) mod 26 = 46 mod 26 = 20 (U)
raw = II[20] = P = 15
output = (15 − 0 + 0 + 26) mod 26 = 41 mod 26 = 15 (P)

── Step 3: Left rotor (III) forward · pos=A(0) ───────────
entry = (15 + 0 − 0 + 26) mod 26 = 41 mod 26 = 15 (P)
raw = III[15] = E = 4
output = (4 − 0 + 0 + 26) mod 26 = 30 mod 26 = 4 (E)

── Step 4: Reflector B · direct table lookup ──────────────
Ref_B[4] = Q = 16 (E pairs with Q — no formula)

── Step 5: Left rotor (III) reverse · pos=A(0) ───────────
entry = (16 + 0 − 0 + 26) mod 26 = 42 mod 26 = 16 (Q)
raw = inv_III[16] = 24 (III[24]=Q, so inverse maps 16→24)
output = (24 − 0 + 0 + 26) mod 26 = 50 mod 26 = 24 (Y)

── Step 6: Middle rotor (II) reverse · pos=A(0) ──────────
entry = (24 + 0 − 0 + 26) mod 26 = 50 mod 26 = 24 (Y)
raw = inv_II[24] = 21 (II[21]=Y, so inverse maps 24→21)
output = (21 − 0 + 0 + 26) mod 26 = 47 mod 26 = 21 (V)

── Step 7: Right rotor (I) reverse · pos=B(1) ────────────
entry = (21 + 1 − 0 + 26) mod 26 = 48 mod 26 = 22 (W)
raw = inv_I[22] = 13 (I[13]=W, so inverse maps 22→13)
output = (13 − 1 + 0 + 26) mod 26 = 38 mod 26 = 12 (M)

── Result ────────────────────────────────────────────────
H (7) → U (20) → P (15) → E (4) → Q (16) → Y (24) → V (21) → M (12)
FINAL OUTPUT: H → M

Step-by-step letter trail

0H→Rotor steps: R advances A→B. Signal enters at H (7).
1H→I→V→URight rotor I fwd · (7+1−0+26)%26=8 · I[8]=V=21 · (21−1+26)%26=20
2U→U→P→PMiddle rotor II fwd · (20+0+26)%26=20 · II[20]=P=15 · (15+26)%26=15
3P→P→E→ELeft rotor III fwd · (15+0+26)%26=15 · III[15]=E=4 · (4+26)%26=4
4E→QReflector B · Ref[4]=Q=16 · direct lookup, no formula
5Q→Q→Y→YLeft rotor III rev · (16+0+26)%26=16 · inv_III[16]=24 · (24+26)%26=24
6Y→Y→V→VMiddle rotor II rev · (24+0+26)%26=24 · inv_II[24]=21 · (21+26)%26=21
7V→W→13→MRight rotor I rev · (21+1−0+26)%26=22 · inv_I[22]=13 · (13−1+26)%26=12
H
→
M
7 substitutions · No plugboard
H(7) U(20) P(15) E(4) Q(16) Y(24) V(21) M(12)
Red = reflector output — the signal reversal point
Verification — self-inverse property: Set the same machine (rotor positions reset to A-A-A, ring 0). Press M. The right rotor will again step to B. Running M through the exact same 7 steps will produce H. The Enigma is its own inverse.
Part 3 of 3
MITM Hardware Implementation
System architecture · Signal flow · config.h · main.c · keyboard scan · injection · complete operation
Section 26

How the complete system operates — start to finish

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:

Domain 1 — Typewriter keyboard: 16 signal lines (8 columns + 8 rows) come from the keyboard FPC into MSP GPIO inputs. The MSP actively scans these by driving each row LOW one at a time and reading which column goes LOW through a pressed key.
Domain 2 — MSP432 processing core: Detects the key, looks up the letter, optionally transforms it through the Enigma cipher engine, then encodes the output letter as a 3-bit column CBA and 3-bit row CBA address.
Domain 3 — Typewriter printer: Two CD4051BE 8-channel analog multiplexers receive the CBA address lines. A CD4066BD bilateral switch (enable line PB3) gates the injection. When the MSP drives the CBA outputs and the enable is HIGH, the printer sees a matrix key event and prints the character.

Complete signal flow — one keypress

1KEY PRESSED→Row + col shorted inside typewriter keyboard
2SCAN→MSP drives rows LOW one at a time, reads col — active col reads LOW
3DECODE→KB_KEYS[row][col] → letter A–Z
4aPASSTHROUGH→output = input, LCD shows same letter on both lines
4bENCRYPT/DEC→enigma_encrypt_char_traced() → output letter, LCD shows in/out
5ENCODE CBA→OUTPUT_COL[letter] and OUTPUT_ROW[letter] → 3-bit binary addresses
6INJECT→PK0-2 (col CBA) + PK3/PA4-5 (row CBA) driven. PB3 always HIGH.
7PRINTER→CD4051 muxes select col and row. Typewriter prints the output letter.
Section 27

System architecture schematic

The diagram below shows how all hardware domains and software modules connect. Arrows show signal or data flow direction.

TYPEWRITER KEYBOARD 8×8 matrix 16 lines row+col MSP432E401Y KEYBOARD SCAN Active row-drive Col WPU read ENIGMA ENGINE 3 rotors + reflector Dual plugboard enigma.c CONTROL PANEL 5 buttons + 2 LEDs Mode / config UI control_panel.c LCD DRIVER NHD-0420D3Z UART6 / PP1 / 9600 MITM INJECT Col CBA PK0-2 Row CBA PK3/PA4-5 Enable PB3 always ON UART DEBUG PA0/PA1 115200 uart_comm.c main.c ORCHESTRATOR get_key() scan_once() drive_row_low() read_col() process_key() enigma_encrypt_char() set_cba() clear_cba() control_panel_update() LCD display PLUGBOARD HW 26 GPIO jacks A-Z Drive-low scan plugboardhw.c NHD-0420D3Z 20×4 LCD display UART6 9600 PuTTY TERMINAL 115200 8N1 UART0 CD4051BE ×2 + CD4066BD Col/Row mux + gate 6 CBA lines + enable 7 lines TYPEWRITER PRINT MECHANISM matrix signal LEGEND GPIO / data signal UART serial Enigma transform CBA injection (7 lines)
Section 28

Module dependency diagram

Every source file, what it depends on, and what depends on it.

main.c orchestrator config.h all pin defs enigma.c cipher engine control_panel.c buttons + LCD UI depends: enigma.h LCD.c UART6 display uart_comm.c debug UART0 plugboardhw.c 26 jack GPIO scan system_check.c boot diagnostics system_msp432e401y.c clock / vector table includes all pins trace output physical plugboard config.h dependency (all files include it) direct include / function call
Section 29

config.h — the single source of truth

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.

Six groups of definitions

GroupWhat it definesUsed by
System globalsg_ui32SysClock, g_tickMs, OperationMode enumAll files
UART / LCDUART0 debug pins, UART6 LCD pins, baud rates, LCD command bytesuart_comm.c, LCD.c
Control panelBTN_MODE/SELECT/UP/DOWN/ENTER pins, LED_GREEN/RED pins, DEBOUNCE_MScontrol_panel.c
Keyboard scanAll 16 col+row scan pins across 5 ports, NMI unlock constants for PD7main.c
MITM outputEN_PIN (PB3), KP_LED (PM0), col CBA pins (PK0-2), row CBA pins (PK3/PA4-5)main.c
Lookup tablesKB_KEYS[8][8] letter map, OUTPUT_COL[26], OUTPUT_ROW[26] CBA tablesmain.c

KB_KEYS — the keyboard decode table

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.

KB_KEYS[2][6] = 'A'   →  row 2 (PE2), col 6 (PC7)
KB_KEYS[3][0] = 'B'   →  row 3 (PE3), col 0 (PE4)
KB_KEYS[4][4] = 'H'   →  row 4 (PD7), col 4 (PE5)

OUTPUT_COL / OUTPUT_ROW — the injection CBA tables

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.

LetterOUTPUT_COL (col CBA index)OUTPUT_ROW (row CBA index)
A6 = CBA 1106 = CBA 110
B3 = CBA 0110 = CBA 000
H4 = CBA 1004 = CBA 100
Z6 = CBA 1104 = CBA 100
Z ambiguity: The typewriter measurement showed col CBA 110/100 for Z. The table uses 110 (index 6). If Z prints the wrong character, change OUTPUT_COL['Z'-'A'] to 4.
Section 30

main.c — the orchestrator

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.

Startup sequence

1
Clock

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.

2
Startup blink

PB4 (green) and PB5 (red) flash 3 times. Confirms GPIO and clock are working before anything else runs.

3
uart_init()

PA0/PA1 configured as UART0 at 115200. From this point all debug output goes to PuTTY.

4
LCD_UART_Init() + LCD_Init()

PP1 configured as UART6 at 9600. LCD boots and shows the idle screen.

5
enigma_init()

Enigma state initialised: Reflector B, rotors I-II-III, positions A-A-A, no plugboard.

6
control_panel_init()

All 5 button pins and 2 LED pins configured. LCD shows idle display.

7
kb_mitm_gpio_init()

All 16 scan inputs configured (row = high-Z, col = WPU). CBA output pins go LOW. PB3 enable goes HIGH. PM0 keypress LED goes LOW.

8
delay_ms(3000)

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.

Main loop — every 10 ms

StepWhat 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-saveIf the control panel leaves the typing screen mid-message, the accumulated characters are saved to history automatically.

process_key() — mode behaviour

ModeLetter inLetter outLCDPuTTY
PASSTHROUGHkey_insame as inBoth lines show same letter[PASS] A
ENCRYPTkey_inenigma_encrypt_char_traced()Line 2 = in, Line 3 = outFull 7–9 step Enigma trace
DECRYPTkey_in (ciphertext)enigma_encrypt_char_traced() — same function, Enigma is self-inverseLine 2 = ciphertext, Line 3 = plaintextFull trace
Section 31

Keyboard matrix scan — active row-drive

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.

Pin configuration

SignalPinsConfigIdle state
Row 0–3PE0 PE1 PE2 PE3Input (high-Z) between scans, output LOW during active scanHigh-Z
Row 4PD7 ⚠ NMISame as above — requires GPIOLOCK unlock sequence at bootHigh-Z
Row 5PD6Input (high-Z) between scansHigh-Z
Row 6–7PM4 PM5Input (high-Z) between scansHigh-Z
Col 0–7PE4 PC4 PC5 PC6 PE5 PD3 PC7 PB2Input + WPU — idle HIGHHIGH

Scan algorithm — scan_once()

for row = 0 to 7:
  set all rows → input (high-Z)
  set this row → output LOW
  wait 20 µs (signal settle)
  for col = 0 to 7:
    if col reads LOW → key at [row][col] pressed
      restore all rows to input
      return KB_KEYS[row][col]
restore all rows to input
return '\0' (no key found)

Debounce — get_key()

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 NMI unlock

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.

HWREG(GPIO_PORTD_BASE + 0x520) = 0x4C4F434B; // write unlock key
HWREG(GPIO_PORTD_BASE + 0x524) |= GPIO_PIN_7; // allow PD7 change
HWREG(GPIO_PORTD_BASE + 0x520) = 0; // re-lock
Section 32

MITM injection — CBA output and enable

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.

Output pin assignments

SignalPinConnectorRole
Col C (bit 2)PK0J7-3CD4051 col mux address bit 2 (MSB)
Col B (bit 1)PK1J7-4CD4051 col mux address bit 1
Col A (bit 0)PK2J7-5CD4051 col mux address bit 0 (LSB)
Row C (bit 2)PK3J7-6CD4051 row mux address bit 2 (MSB)
Row B (bit 1)PA4J7-7CD4051 row mux address bit 1
Row A (bit 0)PA5J7-8CD4051 row mux address bit 0 (LSB)
EnablePB3J1-10CD4066 gate — HIGH permanently from boot
Keypress LEDPM0J8-4ON while key held, OFF on release

set_cba() — encoding a letter index to output pins

col_idx = OUTPUT_COL[letter - 'A'] // e.g. 'A' → 6 = 0b110
row_idx = OUTPUT_ROW[letter - 'A'] // e.g. 'A' → 6 = 0b110

PK0 = (col_idx >> 2) & 1 // col bit 2
PK1 = (col_idx >> 1) & 1 // col bit 1
PK2 = (col_idx ) & 1 // col bit 0
PK3 = (row_idx >> 2) & 1 // row bit 2
PA4 = (row_idx >> 1) & 1 // row bit 1
PA5 = (row_idx ) & 1 // row bit 0

Injection timing

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.

EventWhen
CBA pins driven, PM0 ONImmediately when key detected (after 20 ms debounce)
CBA heldWhile scan_once() keeps finding the same key pressed
CBA cleared, PM0 OFFImmediately when scan_once() returns '\0' (key released)
Why enable is always HIGH: The original design pulsed the enable line per injection. Testing showed the typewriter printer responds correctly as long as the CBA address is stable when the matrix signal changes. Keeping enable permanently HIGH simplifies timing and eliminates the risk of missing the printer's sampling window.

PuTTY output per keypress

PuTTY — ENCRYPT mode, key H pressed
[ENC] H => X (7 changes)
  1. Rfwd: H->Q
  2. Mfwd: Q->E
  3. Lfwd: E->R
  4. Refl: R->B
  5. Lrev: B->T
  6. Mrev: T->W
  7. Rrev: W->X

[INJECT ON] KEY_IN=H KEY_OUT=X COL_CBA=100 ROW_CBA=100
[INJECT OFF]
Section 33

Final system summary — what was built and how it works

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.

Three hardware domains: (1) Keyboard domain — passive 8×8 switch matrix, 16 signal lines from FPC1, scanned by MSP432 active row-drive. (2) Processing domain — MSP432E401Y at 120 MHz, running the Enigma algorithm, control panel FSM, LCD display, and UART debug. (3) Printer domain — CD4051 analog muxes + CD4066 bilateral switch decode 3-bit CBA addresses into physical matrix line selections on FPC2.

Power-on sequence

1
120 MHz clock + SysTick 1 ms

PLL from 25 MHz crystal. All delay_ms() calls depend on this.

2
Startup blink

PB4 (green) + PB5 (red) flash ×3 confirming GPIO is alive before serial output starts.

3
Debug UART — PA0/PA1, 115200 baud

From here every event is logged to PuTTY: key presses, Enigma traces, CBA values, mode changes.

4
LCD boot screen — 5 second system check

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.

5
Enigma init — default UKW-B, rotors I-II-III, positions A-A-A

enigma_init() populates the EnigmaState structure. All rotor inverse tables are precomputed here.

6
Control panel init → LCD switches to PASSTHROUGH idle display

Five buttons and two LEDs configured. LCD now shows mode and rotor positions.

7
MITM GPIO init — EN_PIN (PB3) goes HIGH

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.

8
Plugboard hardware init

26 jack GPIO pins (A–Z) configured as input + WPU. Physical cable pairs are detected and applied to the Enigma state.

Main loop — every 10 ms

TaskWhat 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.
Section 34

Hardware components and their roles

Component Part number Role in system
MicrocontrollerMSP432E401Y120 MHz ARM Cortex-M4F. Runs the entire system: keyboard scan, Enigma cipher, LCD, control panel, CBA injection, UART debug.
TypewriterBrother SX-4000Provides 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 muxCD4051BE ×18-channel analog mux. Receives 3-bit col CBA from PK0-PK2 and selects the corresponding column line on FPC2.
Row muxCD4051BE ×18-channel analog mux. Receives 3-bit row CBA from PK3/PA4/PA5 and selects the corresponding row line on FPC2.
Bilateral switchCD4066BDGates the connection between the selected col and row mux outputs. Enable pin (PB3) driven HIGH permanently from boot — injection path always open.
LCD displayNHD-0420D3Z20×4 character serial LCD. Driven via UART6 at 9600 baud on PP1. Displays mode, rotor positions, plaintext and ciphertext streams in real time.
Plugboard26 NC mono jacksPhysical letter-pair substitution. Normally-closed jacks: empty = LOW (NC to GND), cable inserted = HIGH (WPU). Each jack mapped to one letter A–Z.
Control panel5 buttons + 2 LEDsMODE/SELECT/UP/DOWN/ENTER buttons navigate the configuration FSM. Green LED = ENCRYPT, Red LED = DECRYPT, both off = PASSTHROUGH.
Section 35

Complete GPIO pin assignment — MSP432E401Y

All 51 active GPIO pins across 15 ports. Colour groups match the system architecture.

KEYBOARD SCAN COLUMN INPUTS — input + WPU, idle HIGH, pressed = LOW

PinSignalConnectorFunction
PE4SCAN_COL0J1-2Keyboard matrix col 0
PC4SCAN_COL1J1-3Keyboard matrix col 1
PC5SCAN_COL2J1-4Keyboard matrix col 2
PC6SCAN_COL3J1-5Keyboard matrix col 3
PE5SCAN_COL4J1-6Keyboard matrix col 4
PD3SCAN_COL5J1-7Keyboard matrix col 5
PC7SCAN_COL6J1-8Keyboard matrix col 6 — Return also here at row 1
PB2SCAN_COL7J1-9Keyboard matrix col 7 — Space also here at row 1

KEYBOARD SCAN ROW LINES — toggle high-Z ↔ output LOW

PinSignalConnectorLetters on this row
PE0SCAN_ROW0J3-23— (unmapped)
PE1SCAN_ROW1J3-24Return (col 6), Space (col 7)
PE2SCAN_ROW2J3-25A D G J L
PE3SCAN_ROW3J3-26B I M P R W Y
PD7 ⚠SCAN_ROW4J3-28C F H K S X Z — NMI pin, GPIOLOCK unlock required
PM1SCAN_ROW5J8-2E N O Q T U V — moved from PD6 (PD6 not scanning reliably)
PM4SCAN_ROW6J3-29— (unmapped)
PM5SCAN_ROW7J3-30— (unmapped)

CBA INJECTION OUTPUTS + ENABLE + KEYPRESS LED

PinSignalDirectionFunction
PK0OUT_COL_COutputCol CBA bit 2 (MSB) → CD4051 col mux pin C
PK1OUT_COL_BOutputCol CBA bit 1 → CD4051 col mux pin B
PK2OUT_COL_AOutputCol CBA bit 0 (LSB) → CD4051 col mux pin A
PK3OUT_ROW_COutputRow CBA bit 2 (MSB) → CD4051 row mux pin C
PA4OUT_ROW_BOutputRow CBA bit 1 → CD4051 row mux pin B
PA5OUT_ROW_AOutputRow CBA bit 0 (LSB) → CD4051 row mux pin A
PB3EN_PINOutput HIGH (perm.)CD4066 enable — HIGH from boot, never cleared
PM0KP_LEDOutputJ8-4 — ON while key held, OFF on release

CONTROL PANEL, LEDS, UART, LCD

PinSignalConfigFunction
PB4LED_GREENOutputGreen LED — ON in ENCRYPT mode, ×3 blink at boot
PB5LED_REDOutputRed LED — ON in DECRYPT mode, ×3 blink at boot
PD2BTN_MODEInput + WPUCycle mode: PASSTHROUGH → ENCRYPT → DECRYPT
PQ0BTN_SELECTInput + WPUSelect / confirm menu item
PP4BTN_UPInput + WPUIncrement (rotor, position, plugboard day, ring)
PN5BTN_DOWNInput + WPUDecrement — same parameters as UP
PN4BTN_ENTERInput + WPUEnter config submenus
PA0UART0_RXUART periph.Debug UART receive from PuTTY — 115200 8N1
PA1UART0_TXUART periph.Debug UART transmit — key traces, CBA values, inject log
PP1UART6_TXUART periph.LCD transmit — UART6 at 9600 baud to NHD-0420D3Z

PHYSICAL PLUGBOARD JACKS A–Z — input + WPU, NC jack

LetterPinPort LetterPinPort LetterPinPort
APD0DJPL2LSPM7M
BPM3MKPL1LTPP5P
CPH2HLPL0LUPA7A
DPH3HMPL5LVPQ2Q
EPD1DNPL4LWPQ3Q
FPN2NOPG0GXPQ1Q
GPN3NPPF3FYPM6M
HPP2PQPF2FZPG1G
IPL3LRPF1F
NC jack logic: Empty jack = normally-closed contact shorts tip to GND = pin reads LOW. Cable inserted = NC contact opens = WPU pulls pin HIGH. plugboardhw.c pre-filters at idle (skip LOW pins), then uses drive-LOW confirmation to detect real cable pairs. No phantom pairs from empty jacks are possible.
Section 36

Circuit signal flow tree

How a single keypress travels from physical contact to printed character.

KEYBOARD DOMAIN (FPC1)
 Key switch closes → Row line shorted to Col line
  ↓
MSP432 SCAN (active row-drive)
 MSP drives rows LOW one at a time (PE0-PE3, PD7, PM1, PM4, PM5)
 Columns read via WPU (PE4, PC4-7, PE5, PD3, PB2)
 Pressed key pulls active col LOW → KB_KEYS[row][col] = letter
 Two consecutive matching reads (20 ms debounce) → accepted
  ↓
MODE DECISION (process_key)
 PASSTHROUGH → out = in (no transform)
 ENCRYPT / DECRYPT → enigma_encrypt_char_traced()
   Rotors step → PB1 → R-fwd → M-fwd → L-fwd → Reflect → L-rev → M-rev → R-rev → PB2
  output letter determined
  ↓
CBA ENCODE (set_cba)
 OUTPUT_COL[out-'A'] → 3-bit binary → PK0(C) PK1(B) PK2(A)
 OUTPUT_ROW[out-'A'] → 3-bit binary → PK3(C) PA4(B) PA5(A)
  ↓
INJECTION HARDWARE
 CD4051 col mux: CBA selects 1 of 8 col lines on FPC2
 CD4051 row mux: CBA selects 1 of 8 row lines on FPC2
 CD4066 enable: PB3 permanently HIGH → switch always closed
 Selected col + selected row shorted on FPC2
 CBA held while scan_once() detects key still pressed
 Key released → clear_cba() → all outputs LOW
  ↓
PRINTER DOMAIN (FPC2)
 Typewriter controller detects matrix event on FPC2
 Print mechanism actuates → OUTPUT LETTER PRINTED ON PAPER

CBA encoding reference

How a 3-bit index maps to physical pins. The same encoding is applied to both col (PK0-2) and row (PK3/PA4/PA5).

IndexBinaryC (bit2)B (bit1)A (bit0)
0000000
1001001
2010010
3011011
4100100
5101101
6110110
7111111
Enable strategy: PB3 is HIGH permanently from boot. Injection is controlled entirely by the CBA address lines. When CBA = 000 on both col and row, the muxes select channel 0 which corresponds to an unmapped matrix position — so no character is accidentally printed during idle. Only when set_cba() drives a valid letter address does the printer respond.
Section 37

Keyboard matrix scan map and output CBA tables

Scan matrix — KB_KEYS[row][col]

0-based indices. MSP drives row LOW during scan. Key press pulls col LOW through the switch.

Row \ Col0 (PE4)1 (PC4)2 (PC5)3 (PC6)4 (PE5)5 (PD3)6 (PC7)7 (PB2)
0 (PE0)————————
1 (PE1)——————RETSPC
2 (PE2)——LDJGA—
3 (PE3)BMIPYRW—
4 (PD7⚠)CXKSHFZ—
5 (PM1)VNUOTEQ—
6 (PM4)— all unmapped —
7 (PM5)— all unmapped —

Output CBA lookup table — all 26 letters + Space + Return

LetterCol idxCol CBARow idxRow CBALetterCol idxCol CBARow idxRow CBA
A61102010N10015101
B00003011O30115101
C00004100P30113011
D30112010Q61105101
E51015101R51013011
F51014100S30114100
G51012010T41005101
H41004100U20105101
I20103011V00005101
J41002010W61103011
K20104100X10014100
L20102010Y41003011
M10013011Z61104100
Space71111001Return61101001
Section 38

Software module map — files and responsibilities

FileResponsibilityKey functions
config.hSingle source of truth — every pin, constant, and lookup table. Included by all files. No executable code.KEYS[][], OUTPUT_COL[], OUTPUT_ROW[]
main.cSystem orchestrator. Startup sequence, keyboard scan, process_key(), main loop. Calls all other modules.scan_once(), get_key(), set_cba(), process_key()
enigma.c/hComplete 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/h6-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/hNHD-0420D3Z driver over UART6. Command-prefix protocol at 9600 baud.LCD_Init(), LCD_Print(), LCD_SetCursor()
uart_comm.c/hUART0 debug interface at 115200 baud. uart_putchar, uart_puts, uart_printf.uart_init(), uart_puts(), uart_putchar()
plugboardhw.c/hScans 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.hLegacy 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/hBoot diagnostics. Validates reflector symmetry and no-fixed-point property at startup.system_check_run()
system_msp432e401y.cDevice-specific clock and vector table configuration. Provided by TI SDK example.SystemInit()
Part 4 of 4
Complete System Integration — Final Build
Components · PIN assignments · Circuit description · Power-on sequence · Operation · Project summary
Section 39

Project summary — what this system is and does

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.

Three hardware domains:
Domain 1 — Typewriter keyboard: Passive 8×8 switch matrix. FPC1 connector carries 8 column and 8 row signal lines to the MSP432.
Domain 2 — MSP432E401Y processing core: Scans keyboard, runs Enigma cipher, drives CBA injection, manages LCD and control panel.
Domain 3 — Typewriter printer: Receives injected matrix signals through CD4051 multiplexers and CD4066 switch on FPC2. Prints the output character.

Three operating modes

ModeInputOutputLCD line 2LCD line 3
PASSTHROUGHTyped letterSame letter — identical injectionTyped letterSame letter
ENCRYPTPlaintext letterEnigma-encrypted ciphertext letterPlaintextCiphertext
DECRYPTCiphertext letterPlaintext letter (Enigma is self-inverse)CiphertextPlaintext
Space and Return always bypass the Enigma regardless of mode and inject their own fixed CBA values. They are never encrypted.
Section 40

Hardware components

ComponentPart numberQuantityRole
MicrocontrollerMSP432E401Y LaunchPad1120 MHz ARM Cortex-M4F. Central processor. Keyboard scan, Enigma engine, injection, UI.
TypewriterBrother SX-40001Provides keyboard (passive 8×8 matrix) and daisy-wheel print mechanism.
Analog multiplexerCD4051BE28-channel single-ended mux. One for column selection, one for row selection on FPC2.
Bilateral switchCD4066BD1Gates the injection path. Enable permanently HIGH from boot.
LCD displayNHD-0420D3Z-NSW-BBW120×4 character serial LCD. UART6 at 9600 baud on PP1.
Push buttonsTactile switch5MODE / SELECT / UP / DOWN / ENTER. Control panel navigation.
LEDsStandard 3mm3Green (ENCRYPT mode, PB4), Red (DECRYPT mode, PB5), Keypress indicator (PM0).
Plugboard jacks3.5mm mono NC jack26One per letter A–Z. Normally-closed to GND. Cable insertion opens NC contact.
FPC connectorsMatching to SX-40002FPC1 (keyboard side) and FPC2 (printer side) intercept connectors.
Resistors330Ω3LED current limiting.
Section 41

Complete GPIO pin assignment — all 51 active pins

Group 1 — Keyboard scan column inputs (8 pins) · Input + WPU · Idle HIGH · Pressed = LOW

PinSignalConnectorLetters on this column
PE4col 0J1-2B C V
PC4col 1J1-3M N X
PC5col 2J1-4I K L U
PC6col 3J1-5D O P S
PE5col 4J1-6H J T Y
PD3col 5J1-7E F G R
PC7col 6J1-8A Q W Z · Return
PB2col 7J1-9Space

Group 2 — Keyboard scan row lines (8 pins) · Toggle: Hi-Z ↔ Output LOW during scan

PinSignalConnectorLetters / keys on this rowNote
PE0row 0J3-23— (unused)
PE1row 1J3-24Return (col 6) · Space (col 7)
PE2row 2J3-25A D G J L
PE3row 3J3-26B I M P R W Y
PD7row 4J3-28C F H K S X Z⚠ NMI pin — GPIOLOCK unlock required at boot
PM1row 5J8-2E N O Q T U VMoved from PD6 (PD6 was not scanning reliably)
PM4row 6J3-29— (unused)
PM5row 7J3-30— (unused)

Group 3 — CBA injection outputs (6 pins) · Output · MSP432 → CD4051 muxes

PinSignalRoleNote
PK0OUT_COL_CColumn CBA bit 2 (MSB) → CD4051 col mux pin CAnalog-capable — DEN auto-set by driverlib
PK1OUT_COL_BColumn CBA bit 1 → CD4051 col mux pin B
PK2OUT_COL_AColumn CBA bit 0 (LSB) → CD4051 col mux pin A
PK3OUT_ROW_CRow CBA bit 2 (MSB) → CD4051 row mux pin CAnalog-capable — DEN auto-set by driverlib
PA4OUT_ROW_BRow CBA bit 1 → CD4051 row mux pin B
PA5OUT_ROW_ARow CBA bit 0 (LSB) → CD4051 row mux pin A

Group 4 — Enable and keypress LED (2 pins)

PinSignalConnectorFunction
PB3EN_PINJ1-10CD4066BD enable — HIGH permanently from boot. Never changes.
PM0KP_LEDJ8-4Keypress LED — ON while CBA is driven (key held), OFF on release.

Group 5 — Mode indicator LEDs (2 pins)

PinSignalConnectorFunction
PB4LED_GREENJ2ON in ENCRYPT mode. Flashes ×3 at boot.
PB5LED_REDJ2ON in DECRYPT mode. Flashes ×3 at boot.

Group 6 — Control panel buttons (5 pins) · Active LOW · Input + WPU · Debounced 200 ms

PinSignalFunction
PD2BTN_MODECycle mode: PASSTHROUGH → ENCRYPT → DECRYPT → PASSTHROUGH
PQ0BTN_SELECTSelect / confirm current menu item
PP4BTN_UPIncrement rotor, position, plugboard day, ring setting
PN5BTN_DOWNDecrement same parameters
PN4BTN_ENTEREnter configuration submenus

Group 7 — Debug UART (2 pins) · UART0 · 115200 baud 8N1 · USB virtual COM → PuTTY

PinSignalFunction
PA0UART0_RXReceive from host (currently unused in firmware)
PA1UART0_TXTransmit key trace, CBA values, INJECT ON/OFF, mode changes to PuTTY

Group 8 — LCD UART (1 pin) · UART6 · 9600 baud · NHD-0420D3Z

PinSignalFunction
PP1UART6_TXLCD transmit — command prefix 0xFE, data direct ASCII

Group 9 — Physical plugboard jacks A–Z (26 pins) · Input + WPU · NC jack

Empty jack = NC shorts tip to GND → pin reads LOW. Cable inserted = NC opens → WPU pulls pin HIGH. Pairs confirmed by drive-LOW cross-check between HIGH pins.
LetterPinPortLetterPinPort
APD0DNPL4L
BPM3MOPG0G
CPH2HPPF3F
DPH3HQPF2F
EPD1DRPF1F
FPN2NSPM7M
GPN3NTPP5P
HPP2PUPA7A
IPL3LVPQ2Q
JPL2LWPQ3Q
KPL1LXPQ1Q
LPL0LYPM6M
MPL5LZPG1G
Section 42

CBA injection encoding — all 28 keys

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.

KeyCol CBACol idxRow CBARow idxCol pins (PK0 PK1 PK2)Row pins (PK3 PA4 PA5)
A110601021 1 00 1 0
B000001130 0 00 1 1
C000010040 0 01 0 0
D011301020 1 10 1 0
E101510151 0 11 0 1
F101510041 0 11 0 0
G101501021 0 10 1 0
H100410041 0 01 0 0
I010201130 1 00 1 1
J100401021 0 00 1 0
K010210040 1 01 0 0
L010201020 1 00 1 0
M001101130 0 10 1 1
N001110150 0 11 0 1
O011310150 1 11 0 1
P011301130 1 10 1 1
Q110610151 1 01 0 1
R101501131 0 10 1 1
S011310040 1 11 0 0
T100410151 0 01 0 1
U010210150 1 01 0 1
V000010150 0 01 0 1
W110601131 1 00 1 1
X001110040 0 11 0 0
Y100401131 0 00 1 1
Z110610041 1 01 0 0
Space111700111 1 10 0 1
Return110600111 1 00 0 1
Section 43

Power-on sequence — step by step

1
Clock and SysTick — 120 MHz PLL

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.

2
Startup blink — PB4 green + PB5 red × 3

Both LEDs flash three times before any serial output. Confirms GPIO and clock are working. Visible hardware self-test.

3
Debug UART — UART0 PA0/PA1 at 115200 baud

From this point all events print to PuTTY. The first message is "Booting — 5 s system check..."

4
LCD boot screen — 5 second system check window

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.

5
Enigma engine init — default settings

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.

6
Control panel init — LCD switches to PASSTHROUGH idle display

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.

7
MITM GPIO init — PB3 (EN_PIN) goes HIGH

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.

8
Plugboard hardware init

All 26 jack GPIO pins configured as input + WPU. The NC-jack scan is ready to detect physical cable pairs.

9
Ready — main loop begins

PuTTY receives "Ready. Mode: PASSTHROUGH". The system enters the infinite main loop polling the keyboard every 10 ms.

Section 44

Main loop and complete signal flow per keypress

Keyboard scan — active row-drive

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.

process_key() — the three paths

1PASSTHROUGH→out = key_in → set_cba(OUTPUT_COL[out], OUTPUT_ROW[out]) → same letter injected
2ENCRYPT→out = enigma_encrypt_char_traced(key_in) → set_cba(OUTPUT_COL[out], OUTPUT_ROW[out])
3DECRYPT→same function as ENCRYPT — Enigma is self-inverse
4SPACE/RET→always passthrough regardless of mode → fixed CBA values

Injection hold — tied to physical key

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.

PuTTY output per keypress — ENCRYPT example

PuTTY 115200 — Encrypt mode, key H pressed
[ENC] H => X (7 changes)
  1. Rfwd: H->Q
  2. Mfwd: Q->E
  3. Lfwd: E->R
  4. Refl: R->B
  5. Lrev: B->T
  6. Mrev: T->W
  7. Rrev: W->X
[INJECT ON] KEY_IN=H KEY_OUT=X COL_CBA=100 ROW_CBA=100
[INJECT OFF]

Return key — message save and rotor reset

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.

Section 45

Circuit interconnection description

FPC1 — keyboard to MSP432 (scan input path)

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 — MSP432 to printer (injection output path)

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.

Control panel wiring

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.

LCD connection

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.

Physical plugboard

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.

PD7 NMI unlock: PD7 (row 4 scan line) is the Non-Maskable Interrupt pin, hardware-locked at reset. The firmware writes the unlock key 0x4C4F434B to GPIOLOCK register (offset 0x520), sets bit 7 in GPIOCR (offset 0x524), then re-locks. Without this sequence, all writes to PD7 are silently ignored. GPIO_O_LOCK and GPIO_O_CR are not defined in the MSP432E4 SDK — raw offsets must be used.
PM1 row reassignment: Row 5 (letters E N O Q T U V and Return) was originally assigned to PD6. PD6 was found to be unreliable on this hardware instance — the scan was not triggering correctly. Row 5 was reassigned to PM1 (J8 connector pin 2). This required updating SCAN_D_MASK to remove GPIO_PIN_6, adding GPIO_PIN_1 to SCAN_M_MASK, updating ROW_BASE[5] from GPIO_PORTD_BASE to GPIO_PORTM_BASE, and updating ROW_PIN[5] from GPIO_PIN_6 to GPIO_PIN_1.