Redefence Cipher Encoder/Decoder

Choose a mode, set the rails and key, then enter your text.

How it is calculated

The text is written in a zig-zag over the chosen number of rails (at least 2): rail 1, 2, 3, 2, 1, 2, 3 … Every character counts, including spaces, punctuation and lower case; nothing is removed or changed in case. To encode, each rail is read left to right and the rails are joined in the order given by the key: the first key number names the rail read first, and so on. To decode, the text is cut into rail lengths in that same key order and put back along the zig-zag. The key must list every rail number from 1 to N exactly once, written as 231, 2 3 1 or 2,3,1; if it is empty, the natural order 1, 2, 3 … is used. Wrong key length, repeated or out-of-range numbers give no result. It is a classical puzzle cipher and gives no real security.

Worked example

Encode WEAREDISCOVERED with 3 rails and key 231. Rail 1: W E C R. Rail 2: E R D S O E E. Rail 3: A I V D. Reading rail 2, then rail 3, then rail 1 gives ERDSOEE + AIVD + WECR = ERDSOEEAIVDWECR. Switching to Decode with the same rails and key returns WEAREDISCOVERED.

Try this example →

Common mistakes

  • Decoding with a different number of rails or a different key than was used to encode; both must match exactly, or the output is scrambled.
  • Reading the key as "rail 1 goes to position 2". Here the key lists the rail to read first, second and so on, so 231 starts with rail 2.
  • Writing a key that skips or repeats a rail number (such as 221 or 21 for 3 rails), which the tool rejects.
  • Expecting spaces to be dropped; they are treated like letters, so a message with spaces gives an output with spaces in other places.
  • Pasting ciphertext with a stray trailing space or line break; the extra character shifts the rail lengths and breaks decoding.

About this calculator

The Redefence cipher is a keyed variant of the classic rail-fence cipher. Plaintext letters are written in a zig-zag pattern down and up across N rails (rows), exactly as in a normal rail fence — but instead of reading the rows off in top-to-bottom order, a numeric key determines the order the rails are read in, adding an extra layer of scrambling beyond the basic zig-zag.

Like other rail-fence variants, it's a transposition cipher — it rearranges letters rather than substituting them — and offers only modest security by modern standards. It shows up mainly in cryptography education, puzzle hunts, and CTF (capture-the-flag) challenges as a step up from the plain rail fence, illustrating how adding a key to a simple transposition scheme increases the keyspace an attacker has to search.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    A wrong key does not produce an error as long as it is a valid permutation, only scrambled text, so a puzzle solver can simply try them all: three rails have six possible keys, four rails have 24 and five rails have 120. Counting spaces correctly matters as well. Which puzzle or hunt is this from, and did the plaintext come out readable?

Popular calculators

All Calculators