Results 1 to 2 of 2
- 02-07-2016, 06:17 PM #1
Member
- Join Date
- Feb 2016
- Posts
- 1
- Rep Power
- 0
Exception Errors with double Transposition program
This program prompts a user to choose encrypt, decrypt options. For the encrypt option the user enters a plain text message followed by the number of rows and number of columns then is prompted to enter a row key and column key and then the encypted text is suppose to be printed out . The decrypt option is suppose to do vice-versa. I need my row key be like for example: 3,5,1,4,2 and my column key to be 1,3,2 if the matrix row size is 5 and the column is 3. I am getting exceptions errors in this code and I am stuck and not sure what direction to proceed. Any help would be appreciated, Thanks!
Java Code:import java.io.*; import java.util.*; class NewDoubleTransposition { public static void main(String args[]) { NewEncryptAndDecrypt ned=new NewEncryptAndDecrypt(); ned.input(); } } class NewEncryptAndDecrypt { Scanner sc=new Scanner(System.in); void input() { int ch; do { System.out.println("\n\t\t*****ENTER*****"); System.out.println("\t1.Encrypt"); System.out.println("\t2.Decrypt"); System.out.println("\t0.Exit"); ch=sc.nextInt(); switch(ch) { case 1: { encrypt(); break; } case 2: { decrypt(); break; } } }while(ch!=0); } void encrypt() { String ip,t; char text[][],enc[][]; int key,i,j,row[],col[],r,c; int k=0,m,n; System.out.print("Enter The Plain Text "); ip=sc.next(); t=sc.nextLine(); System.out.print("Enter The Number Of Rows "); r=sc.nextInt(); System.out.print("Enter The Number Of Columns "); c=sc.nextInt(); text=new char[r][c]; enc=new char[r][c]; row=new int[r]; col=new int[c]; for(i=0;i<r;i++) { for(j=0;j<c;j++) { text[i][j]=ip.charAt(k); k++; } } System.out.println("Enter The Row Key "); for(i=0;i<r;i++) row[i]=(sc.nextInt()-1); System.out.println("Enter The Column Key "); for(i=0;i<c;i++) col[i]=(sc.nextInt()-1); k=0; System.out.print("The Cipher Text Is "); for(i=0;i<r;i++) { m=row[i]; for(j=0;j<c;j++) { n=col[j]; enc[i][j]=text[m][n]; System.out.print(""+Character.toUpperCase(enc[i][j])); } } } void decrypt() { String ip,t; char text[][],enc[][]; int key,i,j,row[],col[],r,c; int k=0,m,n; System.out.print("Enter The Cipher Text "); ip=sc.next(); t=sc.nextLine(); System.out.print("Enter The Number Of Rows "); r=sc.nextInt(); System.out.print("Enter The Number Of Columns "); c=sc.nextInt(); text=new char[r][c]; enc=new char[r][c]; row=new int[r]; col=new int[c]; for(i=0;i<r;i++) { for(j=0;j<c;j++) { text[i][j]=ip.charAt(k); k++; } } System.out.println("Enter The Row Key "); for(i=0;i<r;i++) row[i]=(sc.nextInt()-1); System.out.println("Enter The Column Key "); for(i=0;i<c;i++) col[i]=(sc.nextInt()-1); k=0; for(i=0;i<r;i++) { m=row[i]; for(j=0;j<c;j++) { n=col[j]; enc[m][n]=text[i][j]; } } System.out.print("The Retrieved Plain Text Is "); for(i=0;i<r;i++) { for(j=0;j<c;j++) { System.out.print(""+Character.toLowerCase(enc[i][j])); } } } }
- 02-07-2016, 07:54 PM #2
Senior Member
- Join Date
- Mar 2013
- Location
- Greece
- Posts
- 183
- Rep Power
- 7
Similar Threads
-
Transposition Cipher Decryption
By laxbro in forum Advanced JavaReplies: 6Last Post: 01-21-2013, 08:57 PM -
2D Array transposition
By Rederich in forum New To JavaReplies: 7Last Post: 12-02-2011, 09:13 PM -
First Java Program-Compile Errors (errors are posted)-simple GUI
By cc11rocks in forum AWT / SwingReplies: 4Last Post: 01-04-2011, 01:36 AM -
String to double errors
By bigvanilla in forum New To JavaReplies: 9Last Post: 12-05-2010, 09:42 AM -
parseInt Exception errors
By TIMBERings in forum New To JavaReplies: 5Last Post: 12-10-2009, 10:11 AM
Bookmarks