Building Your First Rotor Machine
TL;DR: By chaining multiple , you create a system where the alphabet changes with every single keystroke, making it nearly impossible for a simple pattern-seeker to crack your code.

The Limit of the Single Wheel
In our previous work with basic substitution, we relied on a fixed , like a Caesar shift. You moved the alphabet by three, and it stayed there until you decided to change it. That is a fine starting point, but it is also a fatal weakness. If an attacker sees the letter 'A' turn into 'D' once, they assume it will happen every time. In the world of cryptography, consistency is the enemy. If your code doesn't change as you type, it is just an open door waiting for someone to walk through.
To move beyond this, we need to stop thinking of encryption as a static map and start thinking of it as a moving target. Imagine a clock where the numbers don't just tell time, but actively decide how to scramble the message. When we link multiple wheels together, we aren't just adding complexity; we are creating a machine that possesses a 'memory' of its own state.
The Mechanics of the Multi-Rotor System
Think of your first rotor as a standard alphabet wheel. When you press a key, it rotates one notch. That is simple enough. But what happens if we place a second rotor behind it? Now, the output of the first wheel becomes the input for the second.
Because the second rotor only turns once the first one completes a full revolution, the relationship between your input and output shifts in a way that feels random. This is the heart of mechanical encryption. By stacking three or more rotors, you create a system where the total number of possible positions—the —explodes into the millions. Even if someone knows the design of your wheels, they cannot read your message without knowing the exact starting position of every single disk.
Simulating the Mechanical Shift
To build this yourself, you don't need heavy brass gears. You need a way to track the 'state' of your machine. In computer science, we track this using a variable that increments. Every time you press a key, your program should trigger a function that rotates your virtual disks.
def encrypt_letter(char, rotor_positions):
# Shift the character through each rotor in the chain
for rotor in rotor_positions:
char = rotor.map(char)
# Rotate the first rotor after every keystroke
rotor_positions[0].rotate()
return charThis code mimics the physical reality of a rotor machine. It doesn't just swap letters; it evolves. The first rotor moves every time, the second moves only when the first finishes a cycle, and the third moves when the second finishes. This cascading movement ensures that even if you type the same word twice, the encrypted output will look completely different both times. You have effectively turned a static code into a dynamic, shifting engine.
By layering these wheels, you are participating in a tradition that once decided the outcome of global conflicts. You are no longer just hiding a message; you are building a system that protects itself through constant, mechanical motion. The beauty of this approach is that the complexity doesn't come from the math itself, but from the rhythm of the machine.
By chaining multiple rotors that rotate at different intervals, you transform a predictable substitution code into a dynamic system that changes its logic with every single character typed.
Now that your machine is moving, you might wonder: what happens if someone captures the machine itself? Let’s look at how we can protect the 'settings' of your rotors to ensure that even if the machine is found, the secret remains safe.
Want this with sources you can check?
Premium Learning Paths for Computer Science & AI are researched against open-access libraries — PubMed, arXiv, government databases, and more — with their distinctive claims cited to real sources and independently checked.
See what Premium includes