← Back to challenges
← Recursion: Isolated or Grouped?·Trifid Cipher →

Polybius Square, Bifid Cipher

JavaScriptHardarrayscryptographyloops

Instructions

The basic Polybius Square is a 5x5 square grid with the letters A-Z written into the grid. "I" and "J" typically share a slot (as there are 26 letters and only 25 slots).

12345
1ABCDE
2FGHI/JK
3LMNOP
4QRSTU
5VWXYZ

The Bifid cipher uses the Polybius square but adds a layer of complexity.

Start with a secret message. Remove spaces and punctuation.

plaintext = "ikilledmufasa"

Encipher the message using the basic Polybius cipher (see my previous challenge — right click and select "open in new tab"), but write the numbers in two rows under the message, like so:

ikilledmufasa
2223311342141
4541154251131

Read off the numbers horizontally, in pairs:

22 23 31 13 42 14 14 54 11 54 25 11 31

Generate the ciphertext by converting these new pairs of numbers into new letters using the Polybius square.

ciphertext = "ghlcrddyaykal"

Create a function that takes a plaintext or ciphertext, and returns the corresponding ciphertext or plaintext.

Examples

bifid("I killed Mufasa!") ➞ "ghlcrddyaykal"

bifid("ghlcrddyaykal") ➞ "ikilledmufasa"

bifid("hi") ➞ "go"

Notes

N/A

javascript
Loading editor…
⌘ ↵ to run
Walks through the solution with reasoning and edge cases.