> For the complete documentation index, see [llms.txt](https://cajac.gitbook.io/ctf-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cajac.gitbook.io/ctf-notes/encoding-and-decoding/rotations/rot13.md).

# Rot13

**ROT13** (Rotate13, "rotate by 13 places", sometimes hyphenated ROT-13) is a simple letter [substitution cipher](https://en.wikipedia.org/wiki/Substitution_cipher) that replaces a letter with the 13th letter after it in the [Latin alphabet](https://en.wikipedia.org/wiki/Latin_alphabet). ROT13 is a special case of the [Caesar cipher](https://en.wikipedia.org/wiki/Caesar_cipher) which was developed in ancient Rome.

Because there are 26 letters (2×13) in the [basic Latin alphabet](https://en.wikipedia.org/wiki/ISO_basic_Latin_alphabet), ROT13 is its own [inverse](https://en.wikipedia.org/wiki/Inverse_function); that is, to undo ROT13, the same [algorithm](https://en.wikipedia.org/wiki/Algorithm) is applied, so the same action can be used for encoding and decoding. The algorithm provides virtually no [cryptographic](https://en.wikipedia.org/wiki/Cryptography) security, and is often cited as a canonical example of [weak encryption](https://en.wikipedia.org/wiki/Weak_encryption).

<figure><img src="https://2500502929-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEwPnwcu7pnz3MWV4siTi%2Fuploads%2FQX3DFgnPkyO3dUZhCwrc%2Fimage.png?alt=media&amp;token=87a0174c-0847-4c7d-908a-f6ad24ee7389" alt=""><figcaption><p>Schema of ROT13</p></figcaption></figure>

## Convert in bash

### rot13 command

There are at least two sets of packages that contains prepacked `rot13` tools:

* [hxtools](https://manpages.debian.org/testing/hxtools/hxtools.7.en.html)
* [bsdgames](https://wiki.linuxquestions.org/wiki/BSD_games)

Install them with either `sudo apt install hxtools` or `sudo apt install bsdgames`.

The tool from `hxtools` installs as `/usr/bin/rot13` and is a script that invokes the `tr` command more or less as described below.

The tool from `bsdgames` installs as `/usr/games/rot13` and calls the `caesar` tool (which is also included in the package) but with a rotation of 13.

After one of these tools have been installed you can run

```bash
┌──(kali㉿kali)-[/mnt/…/picoCTF/picoCTF_2019/Cryptography/13]
└─$ echo 'cvpbPGS{abg_gbb_onq_bs_n_ceboyrz}' | rot13
picoCTF{not_too_bad_of_a_problem}
```

### tr command

Alternatively, you can use the `tr` tool like this

```bash
┌──(kali㉿kali)-[/mnt/…/picoCTF/picoCTF_2019/Cryptography/13]
└─$ echo 'cvpbPGS{abg_gbb_onq_bs_n_ceboyrz}' | tr 'A-Za-z' 'N-ZA-Mn-za-m'
picoCTF{not_too_bad_of_a_problem}
```

## Convert with Binary Refinery

You can convert `ROT13` with [rot](https://binref.github.io/#refinery.rot) from Binary Refinery

```bash
┌──(kali㉿kali)-[~]
└─$ source ~/Python_venvs/Binary_Refinery/bin/activate

┌──(Binary_Refinery)─(kali㉿kali)-[~]
└─$ emit 'cvpbPGS{abg_gbb_onq_bs_n_ceboyrz}' | rot           
picoCTF{not_too_bad_of_a_problem}
```

To rotate another amount than 13 you can supply `rot` with the amount as a parameter

```bash
┌──(Binary_Refinery)─(kali㉿kali)-[~]
└─$ emit 'cvpbPGS{abg_gbb_onq_bs_n_ceboyrz}' | rot 11
ngamARD{lmr_rmm_zyb_md_y_npmzjck}
```

## Convert in Python

You can convert `ROT13` with the codecs module

```bash
┌──(kali㉿kali)-[~]
└─$ python
Python 3.11.9 (main, Apr 10 2024, 13:16:36) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import codecs
>>> print(codecs.encode('Ebgngr zr 13 cynprf!', 'rot_13'))
Rotate me 13 places!
>>> exit()
```

## Convert with online services

You can also convert `ROT13` with one of these online services:

CyberChef: <https://gchq.github.io/CyberChef/#recipe=ROT13(true,true,false,13)>

dcode.fr: <https://www.dcode.fr/rot-13-cipher>

## Resources

Binary Refinery - Documentation: <https://binref.github.io/>

Binary Refinery - GitHub: <https://github.com/binref/refinery/>

codecs library - Python: <https://docs.python.org/3/library/codecs.html>

ROT13 - Wikipedia: <https://en.wikipedia.org/wiki/ROT13>
