> For the complete documentation index, see [llms.txt](https://sarpers-organization.gitbook.io/ctftricks/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sarpers-organization.gitbook.io/ctftricks/_chapter-intro-3/obfuscation/rot13-decoding/trick-0320.md).

# ROT13 Decode String From Source

***

Identify strings encoded with ROT13, often found in web source code, headers, or other challenge artifacts. Once identified, use a readily available online ROT13 decoder or a tool like Cyberchef to quickly reveal the original text. ROT13 (rotate by 13 places) is a simple substitution cipher, providing virtually no cryptographic security, and is a common method for basic obfuscation in CTFs.

Beyond online tools, you can also decrypt a ROT13 encrypted string directly on the terminal using the `tr` command. For example:

```bash
echo "Uryyb Jbeyq" | tr 'A-Za-z' 'N-ZA-Mn-za-m'
```

Many programming languages also offer built-in functions or simple implementations for ROT13. In PHP, the `str_rot13()` function can be used:

```php
<?php
echo str_rot13('test'); // Output: grfg
?>
```

Applying `str_rot13()` to an already ROT13-encoded string will return the original version.

A custom function can also be written in languages like Python to perform the ROT13 transformation:

```python
def rot13(s):
    result = ''
    for char in s:
        if 'a' <= char <= 'z':
            result += chr((ord(char) - ord('a') + 13) % 26 + ord('a'))
        elif 'A' <= char <= 'Z':
            result += chr((ord(char) - ord('A') + 13) % 26 + ord('A'))
        else:
            result += char
    return result
```

This function can then be called with the encoded string:

```python
print(rot13("cvpbPGS{guvf_vf_gbb_rnfl}"))
```
