Question:
Help With Java Question?
Billy
2009-12-08 08:28:48 UTC
I need help with this extra credit problem so i can save my gpa!! haha please help if you know java


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.
Four answers:
Kiran
2009-12-08 14:23:08 UTC
Try this. I am not sure how you want the out put to be. Heres how my program will work. You may change as per your requirements. Email me if you need help.



input :kjiran

output:143131553323





import java.util.*;

public class Help62

{

static char bCipher[][]={{'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'}};

public static void main(String a[])

{

String input="";

Scanner sc = new Scanner(System.in);

System.out.print("Please Enter the text :");

input = sc.next();

System.out.println("The out put is :"+cipherText(input.toUpperCase()));

}



public static String cipherText(String input)

{

String result="";

for(int i=0;i
{

result = result + cipherChar(input.charAt(i));

}

return result;

}



public static String cipherChar(char currentChar)

{

String returnString = "";

for(int i=0;i<5;i++)

{

for(int j=0;j<5;j++)

{

if(currentChar == bCipher[i][j])

{

returnString=Integer.toString(i+1) + Integer.toString(j+1);

}

}

}

if(returnString.equals(""))

return "31";

else

return returnString;

}

}
Michelle
2016-05-26 03:07:24 UTC
For all answers behind your each question you need to go through Java Specifications that were designed when the Java language developers first came up with the idea... Do a google search for Java specification and go through it. I am sure it'll answer to all your WHY's!!!
?
2016-11-11 02:38:49 UTC
Bifid Cipher
AnalProgrammer
2009-12-08 08:42:08 UTC
You may find it easier to follow the process from this link.



Have fun.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...