Caesar cipher tool
Encrypt and decrypt text using the Caesar cipher - a classical substitution cipher where each letter is shifted by a fixed number of positions in the alphabet. Configure the shift value and switch between encryption and decryption modes.
Enter your text and watch the cipher transform in real time. Adjust the shift and mode to encrypt or decrypt.
Configure the cipher
Result of Caesar cipher transformation.
What is the Caesar cipher?
The Caesar cipher is one of the earliest known encryption techniques. It works by replacing each letter in the plaintext with a letter a fixed number of positions down the alphabet. For example, with a shift of 3:
- A becomes D
- B becomes E
- C becomes F
Named after Julius Caesar, who reportedly used this method to communicate with his generals, it is technically a monoalphabetic substitution cipher.
How it works: Each letter of the plaintext is shifted by the same number of positions (the “displacement” or “shift”) along the alphabet. The alphabet wraps around, so with a shift of 3, Z becomes C.
Mathematical representation:
For encryption with shift n:
E(x) = (x + n) mod 26
For decryption with shift n:
D(x) = (x - n) mod 26
Where x is the position of the letter in the alphabet (A=0, B=1, … Z=25).
How to use this tool
- Enter your text in the input field
- Select the shift value (1-25) - this is the number of positions each letter will be moved
- Choose the mode:
- Encrypt: Transform readable text into cipher text
- Decrypt: Transform cipher text back into readable text
- View the result in the output field below
- Copy the output using the copy button
The output updates in real time as you type or change settings.
Common use cases
- Educational purposes: Understanding basic cryptography concepts
- Puzzle solving: Cracking simple coded messages
- CTF challenges: Cybersecurity competitions often use basic ciphers
- Fun encryption: Hiding simple messages from casual readers
- Algorithm demonstration: Teaching substitution cipher principles
Limitations
The Caesar cipher provides minimal security by modern standards. It can be easily broken using:
- Brute force: Only 25 possible shifts to try
- Frequency analysis: Letter patterns remain visible
- Known plaintext: Any known word reveals the shift value
For secure communication, use modern encryption like AES or RSA instead.
Pseudo code
/**
* Caesar Cipher Implementation
* Parameters: text, shift, mode
* Returns: encrypted or decrypted text
*/
function caesarCipher(text, shift, mode) {
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
let result = '';
// Adjust shift based on mode
if (mode === 'decrypt') {
shift = 26 - shift;
}
for (let i = 0; i < text.length; i++) {
let char = text[i];
if (char.toUpperCase() === char) {
// Uppercase letter
let index = alphabet.indexOf(char);
if (index !== -1) {
result += alphabet[(index + shift) % 26];
} else {
result += char;
}
} else if (char.toLowerCase() === char) {
// Lowercase letter
let upper = alphabet.indexOf(char.toUpperCase());
if (upper !== -1) {
result += alphabet[(upper + shift) % 26].toLowerCase();
} else {
result += char;
}
} else {
// Non-alphabetic character
result += char;
}
}
return result;
}
// --- Example Usage ---
// Encrypt with shift 3
console.log(caesarCipher('Hello World', 3, 'encrypt'));
// Output: Khoor Zruog
// Decrypt with shift 3
console.log(caesarCipher('Khoor Zruog', 3, 'decrypt'));
// Output: Hello World
Historical context
The Caesar cipher has been in use for approximately 2000 years. Despite its age, it remains a fundamental concept in cryptography education. Modern encryption algorithms like AES still use substitution principles, albeit with far more complexity and multiple rounds of transformation.
Related Developer Tools
Caesar cipher tool
Encrypt and decrypt text using the Caesar cipher with configurable shift values. Perform classical substitution cipher transformations directly in your browser with real-time output.
Header viewer
Analyze HTTP response headers to quickly check caching status, content type, redirects, and server information.
HTTP Status & Redirection Checker
Check HTTP status codes and trace redirect chains across up to 15 hops. Verify final destinations, intermediate codes, and detect loops.
Query string to JSON
Convert complex URL parameters into structured JSON data. View all query string variables displayed in a clean, easy-to-read table and formatted JSON.
SHA hash calculator
Quickly generate SHA-1, SHA-256, SHA-384, and SHA-512 hashes for text or files up to 500MB. All calculations are performed locally in your browser using the native WebCrypto API, ensuring your data never leaves your device.