Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
4
Semester B.E. Semester VIIi– Computer Engineering
Subject Cryptography and System Security
Subject Professor In- Prof. Sneha Annappanavar
charge
Assisting Teachers Prof. Sneha Annappanavar
Laboratory M 312 A
Experiment 4
Number
Experiment Implement keyed transposition cipher technique- (a) Simple Columnar (b) Double
Title Columnar
Resources / Hardware: Software:
Apparatus Normal PC configuration Java
Required
Objectives In this Experiment, we can understand the concept of Simple Columnar and Double
Columnar and difference between them.
Theory of
Operation (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.
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.
Ciphertext: ROFUTKCAATAT
System.out.print("\n-----Encryption-----\n");
cipherText = encrypt(plainText, cipherText, message, rowCount, columnCount, key);
String ct = "";
for(int i=0; i<columnCount; i++)
{
for(int j=0; j<rowCount; j++)
{
if(cipherText[j][i] == 0)
ct = ct + 'x';
else{
ct = ct + (char)cipherText[j][i];
}
}
}
System.out.print("\nCipher Text: " + ct);
System.out.print("\n\n\n-----Decryption-----\n");
plainText = decrypt(plainText, cipherText, ct, rowCount, columnCount, key);
String pt = "";
for(int i=0; i<rowCount; i++)
{
for(int j=0; j<columnCount; j++)
{
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[][] decrypt(int plainText[][], int cipherText[][], String message, int rowCount,
int columnCount, String key){
int i,j;
int k=0;
Double Columnar:
import java.util.*;
class double{
public static void main(String sap[]){
Scanner sc = new Scanner(System.in);
System.out.print("\n-----Encryption-----\n");
cipherText = encrypt(plainText, cipherText, message, rowCount, columnCount, key);
String ct = "";
for(int i=0; i<columnCount; i++)
{
for(int j=0; j<rowCount; j++)
{
if(cipherText[j][i] == 0)
ct = ct + 'x';
else{
ct = ct + (char)cipherText[j][i];
}
}
}
System.out.print("\nMiddle Text: " + ct);
System.out.print("\n\n\n-----Decryption-----\n");
plainText = decrypt(plainText, cipherText, ct, rowCount, columnCount, key);
String pt = "";
for(int i=0; i<rowCount; i++)
{
for(int j=0; j<columnCount; j++)
{
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;
}
System.out.print("Cipher Array(read column by column): \n");
for(i=0;i<rowCount;i++){
for(j=0;j<columnCount;j++){
System.out.print((char)cipherText[i][j]+"\t");
}
System.out.println();
}
return cipherText;
}
static int[][] decrypt(int plainText[][], int cipherText[][], String message, int rowCount,
int columnCount, String key){
int i,j;
int k=0;
Conclusion:
In this Experiment, we can understand the concept of Simple Columnar and Double
Columnar and difference between them.