Caesar Cipher & ROT13: how it works and how to build one
Encode and decode Caesar shifts, ROT13 and ROT47. This guide explains what happens behind the button and shows the code, so you can build your own.
What it does
Shift every letter by a fixed amount, the classic cipher used by Julius Caesar. ROT13 is a shift of 13 that decodes itself, and ROT47 also scrambles digits and symbols. Try all shifts shows the 25 possible decodings at once, so you can crack an unknown shift.
When to use it
- Puzzles and teaching cryptography
- Hiding spoilers (ROT13)
- Cracking simple ciphers
How to use it
- Pick a mode and shift.
- Paste text.
- Copy the result.
Try it free in your browser, nothing is uploaded: https://eskillsfy.com/tools/caesar-cipher
How it works
A Caesar cipher shifts each letter a fixed number of places in the alphabet, wrapping from Z back to A. Shift by 3 and A becomes D. Decoding shifts the other way.
ROT13 is a shift of 13: because the alphabet has 26 letters, doing it twice gives the original. ROT47 does the same over 94 printable ASCII characters.
Build it yourself
Here is the core of the tool. It has no dependencies unless noted, so you can paste it into any TypeScript or JavaScript project.
caesar.ts (ts)
export function caesar(text: string, shift: number) {
const k = ((shift % 26) + 26) % 26;
return text.replace(/[a-z]/gi, (c) => {
const base = c <= "Z" ? 65 : 97;
return String.fromCharCode(((c.charCodeAt(0) - base + k) % 26) + base);
});
}
// Brute force: try every shift
const all = Array.from({ length: 25 }, (_, i) => caesar(secret, -(i + 1)));
Make it production-ready
- Rank brute-force results by how English they look (letter frequency).
Questions
Is this secure?
No. It is a puzzle and teaching tool. Anyone can try all 25 shifts in seconds.
Free, runs in your browser, nothing is uploaded.