Billy
2009-12-08 08:28:48 UTC
The Bifid cipher uses a 5x5 grid of letters agreed on by the sender and receiver. Each of the 25 letters (I and J are treated as being identical) is identified by its row and column number. For example, L is located at row 4, column 3:
! 1 2 3 4 5
! 1 B G W K Z
! 2 Q P N D S
! 3 I O A X E
! 4 F C L U M
! 5 T H Y V R
Each letter in the unencrypted (plaintext) message is listed with its coordinates in the
grid. The coordinates are listed in two rows: row, then column. These numbers are converted into a single list (all rows followed by all columns). The values in the list are read as pairs of integers (i.e., the first two numbers in the list are read as a single row-column pair).
Finally, each new row-column pair is replaced by its matching letter in the grid. For example, if the new pair was 21, the encrypted message (ciphertext) would contain the letter Q.
Write a small Java program that prompts the user to enter a line of text. You may assume that this input only contains lowercase letters, with no spaces between words. Use the technique described above to encrypt the input string with the Bifid cipher, and print the resulting ciphertext. Your code should use one or more methods to carry out the algorithm; do not put everything into a single main() method! Use a two-dimensional array of characters to store the grid; you may organize this grid in any way that you want.