DEPARTMENT OF COMPUTER ENGINEERING Experiment No.4 Semester B.E. Semester VIIi– Computer Engineering Subject Cryptography and System Security Subject Professor InProf. Sneha Annappanavar charge Assisting Teachers Prof. Sneha Annappanavar Laboratory M 312 A Student Name Roll Number Grade and Subject Teacher’s Signature
Madhura Bartakke 15102B0035
Experiment Number Experiment Title Resources / Apparatus Required
4
Objectives
In this Experiment, we can understand the concept of Simple Columnar and Double Columnar and difference between them.
Theory of Operation
Implement keyed transposition cipher technique- (a) Simple Columnar (b) Double Columnar Hardware: Software: Normal PC configuration Java
(a)Simple Columnar TranspositonTechnique: It is another type of cipher where the order of the alphabets in the plaintext is rearranged to create the ciphertext. The actual plaintext alphabets are not replaced. Algorithm for Encryption: Step1: Write the plain text message row by row in the rectangle of predefined size. Step2: Read the message column by column, but not in the sequential way, we have to follow the key specified to obtain the cipher text. An example is a ‘simple columnar transposition’ cipher where the plaintext is written horizontally with a certain alphabet width. Then the ciphertext is read vertically as shown. For example, the plaintext is “golden statue is in eleventh cave” and the secret random key chosen is “five”. We arrange this text horizontally in table with number of column equal to key value. The resulting text is shown below.
The ciphertext is obtained by reading column vertically downward from first to last column. The ciphertext is ‘gnuneaoseenvltiltedasehetivc’. To decrypt, the receiver prepares similar table. The number of columns is equal to key number. The number of rows is obtained by dividing number of total ciphertext alphabets by key value and rounding of the quotient to next integer value. The receiver then writes the received ciphertext vertically down and from left to right column. To obtain the text, he reads horizontally left to right and from top to bottom row. (b)Double Coumnar Transposition Cipher: The Double Columnar Transposition was introduced is a modification of the Columnar Transposition. It is quite similar to its predecessor, and it has been used in similar situations. The Double Columnar Transposition rearranges the plaintext letters, based on matrices filled with letters in the order determined by the secret keyword. The encryption and decryption can be performed by hand, using a piece of paper and a simple matrix, in a similar way as it is done for the Columnar Transposition. Algorithm for Encryption: Step1: Write the plain text message row by row in the rectangle of predefined size. Step2: Read the message column by column, but not in the sequential way, we have to follow the key specified to obtain the cipher(middle) text. Step3: Repeat the step1 and step2 to generate the cipher text. Ex: Plaintext: attack at four
First transportation: permute rows from (1, 2, 3) to (3, 2, 1) Middle text: fourckatatta
Second transportation: permute columns from (1, 2, 3, 4) to (4, 2, 1, 3)
Ciphertext: ROFUTKCAATAT Program
(a) Simple Columnar import java.util.*; class scol{ public static void main(String sap[]){ Scanner sc = new Scanner(System.in); System.out.print("\nEnter plaintext(enter in lower case): "); String message = sc.next(); System.out.print("\nEnter key in numbers: "); String key = sc.next(); int columnCount = key.length(); int rowCount = (message.length()+columnCount)/columnCount; int plainText[][] = new int[rowCount][columnCount]; int cipherText[][] = new int[rowCount][columnCount]; System.out.print("\n-----Encryption-----\n"); cipherText = encrypt(plainText, cipherText, message, rowCount, columnCount, key); String ct = ""; for(int i=0; i
{ if(plainText[i][j] == 0) pt = pt + ""; else{ pt = pt + (char)plainText[i][j]; } } } System.out.print("\nPlain Text: " + pt); System.out.println(); } static int[][] encrypt(int plainText[][], int cipherText[][], String message, int rowCount, int columnCount, String key){ int i,j; int k=0; for(i=0; i
} return cipherText; }
int
static int[][] decrypt(int plainText[][], int cipherText[][], String message, int rowCount, columnCount, String key){ int i,j; int k=0; for(i=0; i
} Double Columnar: import java.util.*; class double{ public static void main(String sap[]){ Scanner sc = new Scanner(System.in); System.out.print("\nEnter plaintext(enter in lower case): "); String message = sc.next(); System.out.print("\nEnter key in numbers: "); String key = sc.next(); int columnCount = key.length(); int rowCount = (message.length()+columnCount)/columnCount; int plainText[][] = new int[rowCount][columnCount]; int cipherText[][] = new int[rowCount][columnCount]; System.out.print("\n-----Encryption-----\n"); cipherText = encrypt(plainText, cipherText, message, rowCount, columnCount, key); String ct = ""; for(int i=0; i
for(int j=0; j
static int[][] encrypt(int plainText[][], int cipherText[][], String message, int rowCount, int columnCount, String key){ int i,j; int k=0; for(i=0; i
{ int currentCol= ( (int)key.charAt(i) - 48 ) -1; for(j=0; j
Single Columnar:
Double Columnar:
Conclusion: In this Experiment, we can understand the concept of Simple Columnar and Double Columnar and difference between them.