---
title: "Caesar"
description: "Shift every letter by N. Default 3, keyspace 25, and the attack is all of them."
canonical_url: "https://ciphers.agntn.dev/ciphers/caesar"
---
# Caesar

> Shift every letter by N. Default 3, keyspace 25, and the attack is all of them.

<cipher-facts name="caesar">



</cipher-facts>

Every letter moves `shift` places down the alphabet and wraps from Z back to A. Default is 3, the one Suetonius says Caesar used. A shift is an integer from 1 to 25. Zero is the identity and 26 is zero again, both rejected.

```ts
import { create } from "@agntn/ciphers";

const caesar = create("caesar");
caesar.encode("ATTACK AT DAWN").text; // "DWWDFN DW GDZQ"
caesar.encode("Hello, World!", { shift: 7 }).text; // "Olssv, Dvysk!"
caesar.decode("DWWDFN DW GDZQ", { shift: 3 }).text; // "ATTACK AT DAWN"
```

Case survives, punctuation and spaces stay put. Decode with the wrong shift and you get another Caesar, which is why [brute force](https://ciphers.agntn.dev/guide/analysis) exists: `ciphers brute "KHOOR ZRUOG"` prints all 25, and shift 3 reads `HELLO WORLD`.

[ROT-13](https://ciphers.agntn.dev/ciphers/rot13) is this with the shift nailed to 13.


## Sitemap

See the full [sitemap](https://ciphers.agntn.dev/sitemap.md) for all pages.
