You are on page 1of 4

ASSIGNMENT/ASSESSMENT COVER SHEET

Student Name: Rao Noman Zafar

FIRST NAME FAMILY / LAST NAME

Registration Number: BSCS-021R17-49

Course Title Network Security

Computer Science
Department
Class & Semester BSCS -7TH

Assignment
Assessment Item Title: Due Date/Time: 1-06-2020

Tutorial Group (If applicable): Word Count (If applicable):

Lecturer/Tutor Name: Zia ur rehman zia

Extension Granted: Yes No Granted By

I declare that this assessment item is my own work unless otherwise acknowledged and is in accordance
with the University’s academic integrity policy.
I certify that this assessment item has not been submitted previously for academic credit in this or any
other course. I certify that I have not given a copy or have shown a copy of this assessment item to
another student enrolled in the course.
I acknowledge that the assessor of this assignment may, for the purpose of assessing this assignment:
 Reproduce this assessment item and provide a copy to another member of the Faculty; and/or
 Communicate a copy of this assessment item to a plagiarism checking service (which may then retain
a copy of the item on its database for the purpose of future plagiarism checking).
 Submit the assessment item to other forms of plagiarism checking.

I certify that any electronic version of this assessment item that I have submitted or will submit is
identical to this paper version.

Signature:___umair saeed__________ Date:_14-05-2020__


Question No.1

Write a program for encryption and decryption using playfair matrix in any
language.

Encryption code in C Language

#include<stdio.h>
int main(){

  char arr[5][5]={"MONAR","CHYBD","EFGIK","LPQST","UVWXZ"};
  char pt[10];

  int i, j, r1=0, r2=0, c1=0, c2=0;


  printf("Playfair Keymatrix\n");
  for(i=0; i<5; i++)
 {
  for(j=0; j<5; j++)
printf("%c ", arr[i][j]);
  printf("\n");
 }

  printf("Enter your plain text:");


  scanf("%s",pt);
  printf("Your plain text = %s", pt);

  for(i=0; i<5; i++)


 {
  for(j=0; j<5; j++)
  {
    if(arr[i][j] == pt[0])
{
r1=i; c1=j;
}
if(arr[i][j] == pt[1])
{
r2=i; c2=j;
}
  }
 }
  if(r1==r2)
 {
  if(c2==4)
printf("Ciphertext = %c%c \n", arr[r1][c1+1], arr[r2][0]); 
  else
printf("Ciphertext = %c%c \n", arr[r1][c1+1], arr[r2][c2+1]);
 }
  if(c1==c2)
 {
  if(r2==4)

printf("Ciphertext = %c%c \n", arr[r1+1][c1], arr[0][c2]); 


  else
printf("Ciphertext = %c%c \n", arr[r1+1][c1], arr[r2+1][c2]); 
  }  if(r1 != r2 && c1 != c2) 
 {
  printf("\nCiphertext = %c%c \n", arr[r1][c2], arr[r2][c1]); 
 }
  return 0;
}

Decryption code in C Language

#include<stdio.h>
int main()
{

char arr[5][5]={"MONAR","CHYBD","EFGIK","LPQST","UVWXZ"};
char ct[10];

int i, j, r1=0, r2=0, c1=0, c2=0;


printf("Plaifair Keymatrix\n");
for(i=0; i<5; i++)
{
for(j=0; j<5; j++)
printf("%c ", arr[i][j]);
printf("\n");
}

printf("Enter your cipher text:");


scanf("%s",ct);
printf("Your cipher text is %s\n", ct);
for(i=0; i<5; i++)
{
for(j=0; j<5; j++)
{
if(arr[i][j] == ct[0])
{
r1=i; c1=j;
}
if(arr[i][j] == ct[1])
{
r2=i; c2=j;
}
}
}
if(r1==r2)
{
if(c2==0)
printf("Plaintext = %c%c \n", arr[r1][c1-1], arr[r2][4]); 
else
printf("Plaintext = %c%c \n", arr[r1][c1-1], arr[r2][c2-1]); 
}
if(c1==c2)
{
if(r2==0)
printf("Plaintext = %c%c \n", arr[r1-1][c1], arr[4][c2]); 
else
printf("Plaintext = %c%c \n", arr[r1-1][c1], arr[r2-1][c2]); 
}

if(r1 != r2 && c1 != c2) 


{
printf("Plaintext = %c%c \n", arr[r1][c2], arr[r2][c1]); 
}
return 0;
}

You might also like