← Return to StackOverflow.org

Rectangular Transposition

Transposition ciphers do not change any letters in a message, they simply rearrange them. Rectangular Transpositions start out by placing all of the letters of a message to be "encrypted" into a grid. If there are any spaces left over, they are filled with padding characters until the grid is perfectly filled. Once the grid is constructed, you "walk through it" taking letters in a particular sequence, giving you your result.

Confusing? Yeah, it is difficult to describe without an example, so here is a sample message: "Let us hear from you at once concerning jewels". If we decide to place that message into a grid that is five letters across, we end up with something like this:

 L E T U S
 H E A R F
 R O M Y O
 U A T O N
 C E C O N
 C E R N I
 N G J E W
 E L S X X

Note the two X's at the end as padding so that the message fits in the grid. If we "walk" through the grid from left-to-right, top-to-bottom we get the following text: LHRUCCNEEEOAEEGLTAMTCRJSURYOONEXSFONNIWX

If we walk through the grid from right-to-left, top-to-bottom, we get the following text: SFONNIWXURYOONEXTAMTCRJSEEOAEEGLLHRUCCNE

We can even get tricky and alternate the horizontals so that we walk down the first column, up the next coumn, then down the following column. Repeating the direction changes to the end gives us: LHRUCCNELGEEAOEETAMTCRJSXENOOYRUSFONNIWX

As you can see, there are a great many ways to traverse a rectangular grid. This JavaScript tool will help you explore the various options.

Encoding

Message to encode:

Grid width to use:

Padding character:

Method to use:




Encoded result:

Decoding

Message to decode:



(*) Auto Decode does not work so well, especially against alternating transpositions. You are probably better off building the grids and manually looking through them for letter patterns.

Possible decodes: