Network & Information Security
Practical No. 9 Write a Program to implement Simple Columnar Transposition
Technique.
I Practical significance
As introduction to In a columnar transposition, the message is written out in rows of a fixed length,
and then read out again column by column, and the columns are chosen in some scrambled order.
Both the width of the rows and the permutation of the columns are usually defined by a keyword.
Given a plain- Transposition Cipher The Columnar Transposition Cipher is a form of transposition
cipher just like Rail Fence Cipher. Columnar Transposition involves writing the plaintext out in
rows, and then reading the cipher text off in columns one by one.
II Relevant Program Outcome (POs)
PO1 – Basic Knowledge
PO2 – Discipline knowledge
PO3 – Experiments and practice
PO4 – Life-long learning
III Competency and practical Skills
“Understand about the Implementation Simple Columnar Transposition Technique”
This practical is expected to develop the following skills:
1. We have to gain knowledge about Simple Columnar Transposition Technique.
2. We have to learn how to encrypt the massage Simple Columnar Transposition Technique..
3. We have to learn how to decrypt the massage Simple Columnar Transposition Technique..
1. We have to learn how to use Simple Columnar Transposition Technique.
IV Relevant Course Outcome(s)
Analyze the Simple Columnar Transposition Technique. And successfully implement it.
V Practical outcomes
Given information about working of Simple Columnar Transposition Technique
VI Relevant Affective Domain Related Outcomes
a. Follow precautionary measures
b. Demonstrate working as a leader / a team member
c. Follow ethical practices
1
By Prof.R.H.Rathod, Comp.Engg. Deptt., Dr.Panjabrao Deshmukh Polytechnic, Amravati
Network & Information Security
VII Minimum Theoretical Background
In cryptography, a transposition cipher is a method of encryption by which the positions held by
units of plaintext (which are commonly characters or groups of characters) are shifted according
to a regular system, so that the cipher text constitutes a permutation of the plaintext. That is, the
order of the units is changed (the plaintext is reordered). Mathematically a objective function is
used on the characters' positions to encrypt and an inverse function to decrypt..
In a columnar transposition, the message is written out in rows of a fixed length, and then read
out again column by column, and the columns are chosen in some scrambled order. Both the
width of the rows and the permutation of the columns are usually defined by a keyword. For
example, the keyword ZEBRAS is of length 6 (so the rows are of length 6), and the permutation
is defined by the alphabetical order of the letters in the keyword. In this case, the order would
be "6 3 2 4 1 5".
VIII Work situation
a. Faculty must form a group of students.
b. Faculty will demonstrate the use of transposition technique with the help of cryptool.
XI Resources required (Additional)
SN Instrument/Object Specification Quantity Remarks
01 Desktop PC Processor i3 1 / group Yes
02 Software C, Cryptool 1 / group Yes
X Precaution to be followed
2. Handle computer system and peripherals with care.
3. Follow safety precautions.
4. Use software properly.
5. Switch off computer system after completing task.
XI Procedure
Code:
#include<stdio.h>
#include<string.h>
#include<conio.h>
void cipher(int i,int c);
int findMin();
void makeArray(int,int);
char
arr[22][22],darr[22][22],emessage[111],retmessage[111],key
2
By Prof.R.H.Rathod, Comp.Engg. Deptt., Dr.Panjabrao Deshmukh Polytechnic, Amravati
Network & Information Security
[55]; char temp[55],temp2[55];
int k=0;
int main()
{
char *message,*dmessage; int i,j,klen,emlen,flag=0;
int r,c,index,min,rows; clrscr();
printf("Enetr the key\n"); fflush(stdin);
gets(key);
printf("\nEnter message to be ciphered\n");
fflush(stdin);
gets(message);
strcpy(temp,key);
klen=strlen(key);
k=0;
for (i=0; ;i++) {
if(flag==1)
break;
for (j=0;key[j]!=NULL;j++) {
if(message[k]==NULL) {
flag=1;
arr[i][j]='-';
} else {
arr[i][j]=message[k++];
}
}
}
r=i;
c=j;
for (i=0;i<r;i++) {
for (j=0;j<c;j++) {
printf("%c ",arr[i][j]);
}
printf("\n");
}
k=0;
for (i=0;i<klen;i++) {
index=findMin();
cipher(index,r);
}
emessage[k]='\0';
printf("\nEncrypted message is\n");
for (i=0;emessage[i]!=NULL;i++)
printf("%c",emessage[i]);
printf("\n\n");
emlen=strlen(emessage);
rows=emlen/klen
3
By Prof.R.H.Rathod, Comp.Engg. Deptt., Dr.Panjabrao Deshmukh Polytechnic, Amravati
Network & Information Security
rows;
j=0;
for (i=0,k=1;emessage[i]!=NULL;i++,k++) {
//printf("\nEmlen=%d",emlen);
temp2[j++]=emessage[i];
if((k%rows)==0) {
temp2[j]='\0';
index=findMin();
makeArray(index,rows);
j=0;
}
}
printf("\nArray Retrieved is\n");
k=0;
for (i=0;i<r;i++) {
for (j=0;j<c;j++) {
printf("%c ",darr[i][j]);
//retrieving message
retmessage[k++]=darr[i][j];
}
printf("\n");
}
retmessage[k]='\0';
printf("\nMessage retrieved is\n");
for (i=0;retmessage[i]!=NULL;i++)
printf("%c",retmessage[i]);
getch();
return(0);
}
void cipher(int i,int r) {
4
By Prof.R.H.Rathod, Comp.Engg. Deptt., Dr.Panjabrao Deshmukh Polytechnic, Amravati
Network & Information Security
for (j=0;j<r;j++) { {
emessage[k++]=arr[j][i];
}
}
// emessage[k]='\0';
}
void makeArray(int col,int row)
{ int i,j;
for (i=0;i<row;i++) {
darr[i][col]=temp2[i];
}
}
int findMin()
{
int
i,j,min,index
;
min=temp[0]
; index=0;
for (j=0;temp[j]!=NULL;j++) {
if(temp[j]<min) {
min=temp[j];
index=j;
}
}
temp[index]=123;
return(index);
}
Output:
Page No : 5
By Prof.R.H.Rathod, Comp.Engg. Deptt., Dr.Panjabrao Deshmukh Polytechnic, Amravati
Network & Information Security
XII Resources used (Additional)
XIII Observations
List student team members
1…………………………………………… 2……………………………………………
3…………………………………………… 4……………………………………………
Signature of Teacher
Page No : 6
By Prof.R.H.Rathod, Comp.Engg. Deptt., Dr.Panjabrao Deshmukh Polytechnic, Amravati