Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

<p><br />The Bi&#64257;d cipher (see http://en.wikipedia.org/wiki/Bi&#64257;d_ci

ID: 3625873 • Letter: #

Question

<p><br />The Bi&#64257;d cipher (see http://en.wikipedia.org/wiki/Bi&#64257;d_cipher) is a simple technique for <br />encrypting messages. It work by translating letters to their coordinates in a special grid, <br />and then manipulating those coordinates in a particular way.<br />The Bi&#64257;d cipher uses a 5x5 grid of letters agreed on by the sender and receiver. Each of <br />the 25 letters (I and J are treated as being identical) is identi&#64257;ed by its row and column <br />number. For example, L is located at row 4, column 3:<br /> 1 2 3 4 5<br />1 B G W K Z<br />2 Q P N D S<br />3 I O A X E<br />4 F C L U M<br />5 T H Y V R<br />Each letter in the unencrypted (plaintext) message is listed with its coordinates in the <br />grid. The coordinates are listed in two rows: row, then column.<br />These numbers are converted into a single list (all rows followed by all columns). The <br />values in the list are read as pairs of integers (i.e., the &#64257;rst two numbers in the list are <br />read as a single row-column pair).<br />Finally, each new row-column pair is replaced by its matching letter in the grid. For <br />example, if the new pair was 21, the encrypted message (ciphertext) would contain the <br />letter Q.<br />Write a small Java program that prompts the user to enter a line of text. You may <br />assume that this input only contains lowercase letters, with no spaces between words. <br />Use the technique described above to encrypt the input string with the Bi&#64257;d cipher, and <br />print the resulting ciphertext. Your code should use one or more methods to carry out <br />the algorithm; do not put everything into a single main() method! Use a twodimensional array of characters to store the grid; you may organize this grid in any way <br />that you want</p>

Explanation / Answer

public class Cipher { public static void main(String[] args) { try { String line = getLine(); String ciphered = cipherCode(line); System.out.println("Ciphered text is: "+ciphered); } catch (IOException e) { System.out.println("There was some error while getting the input"); e.printStackTrace(); } } public static String cipherCode(String line) { char [][] grid = { {'b', 'g', 'w', 'k', 'z'}, {'q', 'p', 'n', 'd', 's'}, {'i', 'o', 'a', 'x', 'e'}, {'f', 'c', 'l', 'u', 'm'}, {'t', 'h', 'y', 'v', 'r'} }; StringBuffer buffer = new StringBuffer(); for(int i = 0;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote