Name: Dil Prasad Kuwor Roll no. : 064/02 Subject: Cryptography Assignment no. : Lab No. 2
Date: 9/26/2010
Q.4 Use any one Transposition technique for encryption and decryption. Testing Data Encryption Plain Text :- attack postponed until 2 am Cipher Text :- TTNAAPTMTSUOAODWCOIXKNLYPETZ TTNAAPTMTSUOAODWCOIXKNLYPETZ (Key is 4 3 1 2 5 6 7, which is one of permutation of key length 7) Decrypt the same cipher text. Try to use different permuted value as key. Java Code: import java.util.*; class TranspositionCipher { public static void main (String[] args) { System.out.println("*******TRANSPOSITION System.out.println("*******TRANSPOSITION CIPHER*******"); CIPHER*******"); Scanner in = new Scanner(System.in); System.out.println("Enter System.out.println("Enter the choice:"); System.out.println("1. System.out.println("1. Plain text to cipher text."); System.out.println("2. System.out.println("2. cipher text to plain text."); int choice = in.nextInt(); switch(choice) { case 1: findTranspositionCipher(); break; case 2: DecryptTranspositionCipher(); break; default: System.out.println("Invalide System.out.println("Invalide choice"); break; } } public static void findTranspositionCipher() findTranspositionCipher() { char letter[]=new char [25]; Scanner in = new Scanner(System.in); Scanner(System.in); String plainText,cipherText="",jpt="ABCDEFGHIJKL plainText,cipherText="",jpt="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; MNOPQRSTUVWXYZ"; int c=0,l=1,v=0,i=0,t=1,vc=0,r c=0,l=1,v=0,i=0,t=1,vc=0,r=0; =0; char mat[][]=new char[50][50];
1
int key[]={4,3,1,2,5,6,7}; key[]={4,3,1,2,5,6,7}; char z; System.out.println("Enter System.out.println("Enter the plain text:"); plainText=in.nextLine(); for(i=0;i
2
c++; } cipherText=cipherText.toUpperCase(); System.out.println("\nThe System.out.println("\nThe Cipher Text is:\n"+cipherText); } public static void DecryptTranspositionCipher() { Scanner in = new Scanner(System.in); String plainText="",cipherText="",jpt="ABCDEFGHIJ plainText="",cipherText="",jpt="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; KLMNOPQRSTUVWXYZ"; int c=0,l=1,v=0,i=0,j=0,k=0; char mat[][]=new char[50][50]; char pmat[][]=new pmat[][]=new char[50][50]; char[50][50]; int key[]={4,3,1,2,5,6,7}; key[]={4,3,1,2,5,6,7}; char z; System.out.println("Enter System.out.println("Enter the Cipher text:"); cipherText=in.nextLine(); v=(cipherText.length()/key.length); while(c
3
Output: 1. Encryption
2. Decryption
The
End
4