Message Boards Message Boards

Visually resolving workflow of polyalphabetic enciphering

Dear Community,


I would like to develop an applet that animates intermediate steps on the tabula recta for the Vigénere cipher. 

The Vigénere (and Gronsfeld) cipher is a polygraphic substitution cipher that successfully resisted attack for ~300yrs. Plaintext is enciphered through a tableau (the 'tabula recta'): 
alphabet = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",    "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X",    "Y", "Z"};
my\[Alpha]\[Beta]Len[\[Alpha]\[Beta]Len_] :=   Table[RotateLeft[alphabet, i], {i, 0, \[Alpha]\[Beta]Len}];
TableForm[my\[Alpha]\[Beta]Len[Length[alphabet] - 1], 
 TableHeadings -> {alphabet, alphabet}]


I would like to highlight the row and column of the tuples generated by the Mathematica implentation of the enciphering process (truncated for clarity):
Partition[Riffle[{"A", "R", "J"}, {"M", "A", "T"}], 2]
that index the tableu elements (substitution prescription). When the table is deployed in a Matrix-formatted grid structure, the coloring rules are straightforward to implement, resulting in:
alphaMatrix = Grid[my\[Alpha]\Len[Length[alphabet] - 1],
   Background -> {3 -> LightRed, 5 -> LightBlue, {5, 3} -> LightGreen},
   Dividers -> {{True, False}, {True, False}}] // MatrixForm

I may be mistaken, but I believe the MatrixForm allows me to iteratitively-extract elements from the data structure. However, I  lose my axis label discretion, which may obfuscate the logic behind the algorithm. I attempted to wrap a TableForm around a gridded, iterated table generation, but was unable to capture the mutually-exclusive functionality of both (that is, the indices spanning two sides and the block coloring)
 alphabet = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", 
    "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", 
    "Y", "Z"};
 my\[Alpha]\[Beta]Len[\[Alpha]\[Beta]Len_] := 
   Table[RotateLeft[alphabet, i], {i, 0, \[Alpha]\[Beta]Len}];
 alphaMatrix = 
   Grid[my\[Alpha]\[Beta]Len[Length[alphabet] - 1], 
    Background -> {3 -> LightRed, 
      5 -> LightBlue, {5, 3} -> LightGreen}] // MatrixForm;

TableForm[alphaMatrix, TableHeadings -> {alphabet, alphabet}]

The resulting graph was useless (perhaps TableForm can't mutate Grid structs?) If anybody could be so kind as to help me highlight the ith row and jth column in a grid structure and extend the range of those highlights to the index components of the lookup table (static axis labels), I would be exceedingly grateful. 

Warn regards,
Arjan Singh Puniani
POSTED BY: Arjan Puniani
I think you want to stick with Grid here and avoid MatrixForm and TableForm altogether.  With a bit of array manipulation, you can add the row/column headers to the list and they will display when you wrap them in Grid[ ].  This function written below will take one such array and then row/column headers, and construct an array suitable for use in Grid iff the arguments have the same Length[ ].
addHeaders[array_, xheads_, yheads_] :=
  (* Make sure that Length[array] === Length[xheads] === Length[yheads] *)
  Transpose[Prepend[Transpose[Prepend[array, xheads]], Prepend[yheads, ""]]]

Then, using:
array = my??Len[Length[alphabet] - 1];

You can see the grid coming together with:
Grid[addHeaders[array, alphabet, alphabet]]

Add dividers:
Grid[addHeaders[array, alphabet, alphabet], Dividers -> {{2->True}, {2->True}}]

And the coloring example you gave:
Grid[addHeaders[array, alphabet, alphabet], Dividers -> {{2->True}, {2->True}},
  Background -> {3 -> LightRed, 5 -> LightBlue, {5, 3} -> LightGreen}]

You can add other Grid options if you'd like: Spacings if you want to control the space between successive rows / columns, etc.

Hope this helps,
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract