Caesar Cipher oleh Manisha Arie

Modular Addition Cryptography Simulator

{{ mode === 'encrypt' ? 'PLAINTEXT' : 'CIPHERTEXT' }}

Static Result Preview

Type input text to see result... {{ staticOutput }}

Select Key Shift Value

Choose how many positions to shift the alphabet (0 to 25).

Shift Key (K)
(= {{ numToChar(shiftKey) }})
{{ n }}
Quick Presets

Horizontal Alphabet Shift Map

See how letters align with a shift of {{ shiftKey }} positions. Hover over any letter mapping.

Shift Value (K):
Plaintext Track (A-Z)
{{ String.fromCharCode(65 + n - 1) }}
{{ n - 1 }}
Ciphertext Track (Shifted by {{ shiftKey }} {{ mode === 'encrypt' ? 'forward' : 'backward' }})
{{ numToChar(getShiftedValue(n - 1)) }}
{{ getShiftedValue(n - 1) }}

Interactive Simulation Trace

Trace the character shift addition/subtraction step-by-step.

{{ totalBlocks }} Characters Char {{ activeBlockIndex + 1 }} of {{ totalBlocks }} {{ mode.toUpperCase() }} (K = {{ shiftKey }})
Character Shifting Layout
Input
{{ currentInputChar || '_' }} {{ currentInputChar ? charToNum(currentInputChar) : '?' }}
Shift
{{ mode === 'encrypt' ? '+' : '-' }} {{ shiftKey }}
Output
{{ activeSubStep >= 4 ? currentOutputChar : '_' }} {{ activeSubStep >= 3 ? currentOutputVal : '?' }}
Calculation Trace
Modular Arithmetic Step Formula: {{ mode === 'encrypt' ? 'C = (P + K) mod 26' : 'P = (C - K) mod 26' }}
1. Map Character to Value: {{ currentInputChar || '?' }} → {{ currentInputChar ? charToNum(currentInputChar) : '?' }}
2. Apply Shift: {{ currentInputChar ? charToNum(currentInputChar) : '?' }} {{ mode === 'encrypt' ? '+' : '-' }} {{ shiftKey }} = {{ currentInputChar ? (mode === 'encrypt' ? charToNum(currentInputChar) + shiftKey : charToNum(currentInputChar) - shiftKey) : '?' }}
3. Modulo 26: ({{ currentInputChar ? (mode === 'encrypt' ? charToNum(currentInputChar) + shiftKey : charToNum(currentInputChar) - shiftKey) : '?' }}) mod 26 = {{ activeSubStep >= 3 ? currentOutputVal : '?' }}
4. Resulting Character: {{ activeSubStep >= 3 ? currentOutputVal : '?' }} → {{ activeSubStep >= 4 ? currentOutputChar : '?' }}
Playback Center Speed: {{ animationSpeed }}ms
1. Read Char 2. Map to Num 3. Shift Val 4. Modulo 26 5. Map to Char
Speed
Character Progress Tracker
Live Accumulation Result {{ finalOutput || '...' }}
Completed!

How the Caesar Cipher Works Mathematically

Learn the modular arithmetic and algebraic equations behind this historical shift cipher.

1. Encryption Equation

Ci = (Pi + K) mod 26

Each plaintext character index Pi (0 for A, 25 for Z) is shifted forward by the key K. The mod 26 operation wraps any overflow back to the beginning of the alphabet.

2. Decryption Equation

Pi = (Ci - K) mod 26

Each ciphertext character index Ci is shifted backward by K. In modular arithmetic, if subtracting K results in a negative number, we add 26 to ensure the result falls within [0, 25].

3. ROT13 (Special Case)

ROT13 uses a shift key of K = 13. Because 13 is exactly half of the 26-letter alphabet, encryption and decryption are reciprocal operations:

(X + 13) + 13 = X + 26 ≡ X mod 26

This means applying ROT13 twice to any input returns the original plaintext.

Historical Fact

Named after Julius Caesar, who used it with a shift of 3 to communicate state messages secretly. While insecure today due to only having 25 possible keys (which are easily brute-forced), it serves as the foundational building block for many modern block ciphers.

Alphabet-to-Number Index Reference Chart (A-Z)

{{ String.fromCharCode(64 + n) }}
{{ n - 1 }}