🔐 ROT13 Encoder & Decoder
Transform text using the self-reversible ROT13 cipher - Perfect for hiding spoilers and basic text obfuscation
🎯 ROT13 Alphabet Mapping
ROT13 replaces each letter with the letter 13 positions after it. Since there are 26 letters, applying ROT13 twice returns the original text.
🏛️ What is ROT13?
ROT13 ("rotate by 13 places") is a special case of the Caesar cipher with a fixed shift of 13. It's widely used in online forums and newsgroups to hide spoilers, puzzle solutions, and punchlines.
Simple substitution cipher
Each letter is replaced by another letter 13 positions away in the alphabet.
Self-reversible
Apply ROT13 twice to get the original text back - same operation for encoding and decoding.
Case-preserving
Uppercase letters remain uppercase, lowercase letters remain lowercase.
Widely supported
Used across platforms, forums, and text editors for quick obfuscation.
⚙️ How It Works
Each letter is replaced by the letter 13 positions ahead in the alphabet. When reaching the end, it wraps around to the beginning:
- A ↔ N, B ↔ O, C ↔ P, etc.
- Numbers and symbols remain unchanged (unless option enabled)
- Mathematical formula: (x + 13) mod 26
- Same process for encoding and decoding
🔐 Security & Usage
ROT13 provides no cryptographic security and is trivially broken. However, it's perfect for: and is trivially broken. However, it's perfect for:
🎬 Hiding spoilers
Prevent accidental reading of movie, book, or game spoilers in forums.
📧 Email obfuscation
Obscure email addresses from spam bots on websites.
🎓 Teaching cryptography
Introduce basic encryption concepts to students.
🎮 Puzzles & games
Create simple word puzzles and riddles.
❓ Frequently Asked Questions
💻 ROT13 in Different Programming Languages
Python
import codecs
# Method 1: Using codecs
text = "Hello World"
encoded = codecs.encode(text, 'rot13')
print(encoded) # Output: Uryyb Jbeyq
# Method 2: Manual implementation
def rot13(text):
result = []
for char in text:
if char.isalpha():
offset = 65 if char.isupper() else 97
result.append(chr((ord(char) - offset + 13) % 26 + offset))
else:
result.append(char)
return ''.join(result)
print(rot13("Hello World")) # Output: Uryyb Jbeyq
JavaScript
function rot13(str) {
return str.replace(/[a-zA-Z]/g, function(char) {
const code = char.charCodeAt(0);
const offset = code >= 65 && code <= 90 ? 65 : 97;
return String.fromCharCode((code - offset + 13) % 26 + offset);
});
}
console.log(rot13("Hello World")); // Output: Uryyb Jbeyq
PHP
<?php
// Method 1: Using str_rot13
$text = "Hello World";
$encoded = str_rot13($text);
echo $encoded; // Output: Uryyb Jbeyq
// Method 2: Manual implementation
function rot13_manual($str) {
$result = '';
for ($i = 0; $i < strlen($str); $i++) {
$char = $str[$i];
if (ctype_alpha($char)) {
$offset = ord(ctype_upper($char) ? 'A' : 'a');
$result .= chr((ord($char) - $offset + 13) % 26 + $offset);
} else {
$result .= $char;
}
}
return $result;
}
?>
Java
public class ROT13 {
public static String encode(String text) {
StringBuilder result = new StringBuilder();
for (char c : text.toCharArray()) {
if (Character.isLetter(c)) {
char offset = Character.isUpperCase(c) ? 'A' : 'a';
result.append((char) ((c - offset + 13) % 26 + offset));
} else {
result.append(c);
}
}
return result.toString();
}
public static void main(String[] args) {
System.out.println(encode("Hello World"));
// Output: Uryyb Jbeyq
}
}
C++
#include <iostream>
#include <string>
#include <cctype>
std::string rot13(const std::string& text) {
std::string result;
for (char c : text) {
if (std::isalpha(c)) {
char offset = std::isupper(c) ? 'A' : 'a';
result += (c - offset + 13) % 26 + offset;
} else {
result += c;
}
}
return result;
}
int main() {
std::cout << rot13("Hello World") << std::endl;
// Output: Uryyb Jbeyq
return 0;
}
Linux/Unix Command Line
# Using tr command
echo "Hello World" | tr 'A-Za-z' 'N-ZA-Mn-za-m'
# Output: Uryyb Jbeyq
# Decode (same command)
echo "Uryyb Jbeyq" | tr 'A-Za-z' 'N-ZA-Mn-za-m'
# Output: Hello World
# Process a file
cat input.txt | tr 'A-Za-z' 'N-ZA-Mn-za-m' > output.txt
📚 Historical Context
ROT13 became popular on Usenet in the 1980s as a way to hide potentially offensive content. It's described as the "Usenet equivalent of printing an answer upside down."
- Originated in early internet culture
- Still used in modern forums and discussion boards
- Built into many text editors (like Vim)
- Standard in Unix utilities
🔗 Related Cipher Tools
🔄 Caesar Cipher
Classic shift cipher with customizable shift values (1-25). More flexible than ROT13.
🔀 Atbash Cipher
Ancient Hebrew cipher that reverses the alphabet (A↔Z, B↔Y). Another self-reversible method.
🔐 Vigenère Cipher
Polyalphabetic cipher using keyword-based encryption for more advanced security.
📊 Base64 Encoder
Convert binary data to ASCII text representation for safe data transmission.