---
title: "Playfair"
description: "Letter pairs through a keyed 5×5 table. J folds into I, doubled pairs are split with X, odd length is padded with X."
canonical_url: "https://ciphers.agntn.dev/ciphers/playfair"
---
# Playfair

> Letter pairs through a keyed 5×5 table. J folds into I, doubled pairs are split with X, odd length is padded with X.

<cipher-facts name="playfair">



</cipher-facts>

The key fills a 5×5 table, duplicates dropped, rest of the alphabet after it, J folded into I to fit 25 cells. The text is stripped to letters and cut into pairs. Same row - move right. Same column - move down. Otherwise each letter takes the other's column. Two identical letters in a pair get split with an X, and an odd final letter is paired with X. Output is uppercase without spaces, because the input has been reshaped anyway.

```ts
const playfair = create("playfair");
playfair.encode("HIDE THE GOLD IN THE TREE STUMP", { key: "PLAYFAIR EXAMPLE" }).text;
// "BMODZBXDNABEKUDMUIXMMOUVIF"
playfair.decode("BMODZBXDNABEKUDMUIXMMOUVIF", { key: "PLAYFAIR EXAMPLE" }).text;
// "HIDETHEGOLDINTHETREXESTUMP"
```

The round trip keeps the X that split `TREE`. That's the cipher, not a bug, and every Playfair implementation that claims otherwise is guessing. Key is required and must contain letters. The Wikipedia vector above is the one the test suite checks.


## Sitemap

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