SlideShare a Scribd company logo
1 of 12
Download to read offline
Solutions to Assignment #1

              ECE 6106
        Computer NW Security



         By: Khalid El-Darymli
        Matric. No.: G0327887




               ECE Dept.
         Faculty of Engineering
          URL: eng.iiu.edu.my

International Islamic University Malaysia
a- Plain Text: “engineering excellence”
 Encryption using Caesar’s cipher: HQJLQHHULQJ HAFHOOHQFH




b- Program for problem # 1:

//Program for problem# 1:
#include<iostream.h>
#include<string.h>
#include<stdio.h>
#define w 10000
#include<conio.h>
char b[w];
int chick(void);
void main()
{
void encrypt(void), decrypt(void);
char op;

cout<<quot;THIS PROGRAM CALCULATING THE ENCRYPTION OR DECRYPTION OF ENTERED
STRINGquot;;
cout<<quot; USING CAESAR's MOEHOD quot;<<endl;
cout<<quot;|**********************************************************************|quot;<<endl;
cout<<quot;Please Choose your CHOICEquot;<<endl;
cout<<quot;To ENCRYPT PLEASE PREES E >>>>quot;<<endl;
cout<<quot;To DECRYPT PLEASE PRESS D >>>quot;<<endl;
cout<<quot;TO EXIT PLEASE PRESS any other keyquot;<<endl;
cin>>op;
clrscr();
switch(op)
{
case 'e':case 'E': encrypt();break;
case 'd': case 'D': decrypt();break;
default: break;
}

}



/*THE FUNCTION OF ENCRYPTION            */
void encrypt()
{
int i,s;
char *p,c[w],n;
cout<<quot;please enter the text to be encrypt:quot;<<endl;
aa:
gets(b);

if(chick()==1)
{cout<<quot;SORRY,ERROR IN THE INPUT DATA>>please RENTER the Ciphered text should be
alphabetic text quot;<<endl;
goto aa;}
for(i=0;i<=strlen(b);i++)
{
s=0;
p=&b[i];
if(*p==32||*p=='0')
{s=1;n=32;}
if(*p>=97&&*p<=119)
{s=1,n=*p%97+68;}
if(*p>=120&&*p<=122)
{s=1,n=*p%120+65;}
if(*p>=65&&*p<=87)
{s=1,n=*p+3;}
if(*p>=88&&*p<=90)
{s=1,n=*p%88+65;}
c[i]=n;
if(s==0)
{cout<<quot;YOU ENTERED NON-ALPHABETIC SYMBOL, ALL ENTERS SHOULD BE ALPHABETIC
LETTERSquot;<<endl;
goto xx;}
 }
for(i=0;i<=strlen(b);i++)
cout<<c[i];
xx:
}
//THE FUNCTION OF MAKING DECRYPTION
void decrypt()
{
int i,s;
char *p,c[w],n;
cout<<quot;enter the text to be decryptquot;<<endl;
aa:
gets(b);
if(chick()==1)
{cout<<quot;SORRY,ERROR IN THE INPUT DATA>>please RENTER the Ciphered text should be
alphabetic text quot;<<endl;
goto aa;}
for(i=0;i<=strlen(b);i++)
{
s=0;
p=&b[i];
if(*p==32||*p=='0')
{s=1;n=32;}
if(*p>=100&&*p<=122)
{s=1,n=*p-3;}
if(*p>=97&&*p<=99)
{s=1,n=120-*p%97;}
if(*p>=68&&*p<=90)
{s=1,n=*p%68+97;}
if(*p>=65&&*p<=67)
{s=1,n=120-*p%65;}
c[i]=n;
if(s==0)
{cout<<quot;YOU ENTERED NON-ALPHABETIC SYMBOL, ALL ENTERS SHOULD BE ALPHABETIC
LETTERSquot;<<endl;
goto xx;}
 }
for(i=0;i<=strlen(b);i++)
cout<<c[i];
xx:
}

//Function chick, this function chicks the input data to make sure THAT they are
//pure alphabetics WITH OR WITHOUT SPACES
        int chick(void)
        { int test,i;
                        for(i=0;i<strlen(b);i++)
        if((b[i]>=65&&b[i]<=90)||(b[i]>=97&&b[i]<=122)||(b[i]==32))
        test=0;
        else
        {
        test=1;
        return test;
}
return test;
}
3-Program for problem # 3:
//Program for problem# 3:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#define w 10000
char pt[w],kt[w],ct[w],ch[w];
char vignere_table_cipher(char,char);
char vignere_table_decipher(char,char);
 int chick(void);
void main(){
char op;
void cipher(void);
void decipher(void);

cout<<quot;THIS PROGRAM PERFORMS ENCRYPTION OR DECRYPTION FOR ENTERED TEXT
usingquot;;
cout<<quot;Vigenere's autokey cipherquot;<<endl<<endl;
cout<<quot;|**********************************************************************|quot;<<endl;
cout<<quot;Please Choose your CHOICEquot;<<endl;
cout<<quot;[E] For ENCRYPTION please <<Press E followed by enter quot;<<endl;
cout<<quot;[D] For DECRYPTION please <<PRESS D followed by enterquot;<<endl;
cout<<quot; For EXIT please press any other key followed by enterquot;<<endl;
cin>>op;
switch(op)
{
case 'e': case 'E':cipher();break;
case 'd': case 'D':decipher();break;
default: break;
}}
//Ciphering function: This function performs encryption
void cipher(void)
{
int x,n,i;
char mkt[w],ct[w];
char *pp,*kp;
clrscr();
cout<<quot;Enter the text to be Encrypt:>>PLEASE REMOVE SPACES:quot;<<endl;
aa:
gets(pt);
strcpy(ch,pt);
if(chick()==1)
{cout<<quot;SORRY,ERROR IN THE INPUT DATA>>please RENTER just alphabetic text without
spacesquot;<<endl;
goto aa;}
cout<<quot;Enter the Encryption key:>>PLEASE REMOVE THE SPACES:quot;<<endl;
strcpy(ch,quot; quot;);
bb:
gets(kt);
strcpy(ch,kt);
if(chick()==1)
{cout<<quot;SORRY,ERROR IN THE INPUT DATA>>please RENTER just alphabetic text without
spacesquot;<<endl;
goto bb;}
 for (i=0; i<strlen(pt); i++)
          pt[i] = tolower(pt[i]);
         for(i=0;i<strlen(kt);i++)
         kt[i]=tolower(kt[i]);

 //Making the length of key equal to the length of plain text
x=strlen(pt);
xx:
x-=strlen(kt);
if(x>=0)
{n=strlen(kt);
strncat(mkt,kt,n);
goto xx; }
else
strncat(mkt,kt,x+strlen(kt));
// end of process

//Ciphering and printing of the plaintext
 for(i=0;i<strlen(pt);i++)
 {
 pp=&pt[i];
 kp=&mkt[i];
ct[i]=vignere_table_cipher(*pp,*kp);
 }
printf(quot;nquot;);
for(i=0;i<strlen(ct);i++)
ct[i]=toupper(ct[i]);
 puts(ct);

 }
//End of process

//This function calculating the character corresponding to that we obtain fro Vignere Table
//for two submitted character, the key character and the plain text text character
//the function returns the ciphered character
char vignere_table_cipher(char k,char p)
{
char c;
int d,comp;
comp=k-'a';
d=p+comp;
if(d>122)
{d%=122;
d+=96;}
c=d;
return c;
}

 //Function decipher, this function perofoms decryption.
void decipher(void)
{
 int x,n,i;
char mkt[w],dt[w];
char *pp,*kp,rvv;
clrscr();
cout<<quot;Enter the text to be DECRYPT:>>PLEASE remove the spaces>>quot;<<endl;
aa:
gets(ct);
strcpy(ch,ct);
if(chick()==1)
{cout<<quot;SORRY,ERROR IN THE INPUT DATA>>please RENTER the Ciphered text just alphabetic
text without spacesquot;<<endl;
goto aa;}
strcpy(ch,quot; quot;);
cout<<quot;Enter the DECRYPTION key:>>PLEASE REMOVE THE SPACES>>quot;<<endl;
bb:
gets(kt);
 strcpy(ch,kt);
if(chick()==1)
{cout<<quot;SORRY,ERROR IN THE INPUT DATA>>please RENTER the KEY just as alphabetic text
without spacesquot;<<endl;
goto bb;}
for (i=0; i<strlen(ct); i++)
                  ct[i] = tolower(ct[i]);
        for(i=0;i<strlen(kt);i++)
        kt[i]=tolower(kt[i]);

         //Making the length of key equal to the length of cipheered text
x=strlen(ct);
xx:
x-=strlen(kt);
if(x>=0)
{n=strlen(kt);
strncat(mkt,kt,n);
goto xx; }
else
strncat(mkt,kt,x+strlen(kt));
// end of process

//deCiphering and printing of the plaintext
 for(i=0;i<strlen(ct);i++)
 {
 pp=&ct[i];
 kp=&mkt[i];
dt[i]=vignere_table_decipher(*kp,*pp);
 }
printf(quot;nquot;);
 puts(dt);
 }
//End of process

//This function calculating the character corresponding to that we obtain from Vignere Table
//for two submitted character, the key character and the ciphered text character
 //the function returns the plain text character
char vignere_table_decipher(char kt,char ct)
 {
char d;
int comp,pt;
comp=kt-'a';
pt=ct-comp;
if(pt<97)
pt+=123-97;
d=pt;
return d;
}
//End of function



//Function chick, this function chicks the input data to make sure they are
//pure alphabetics and without spaces
        int chick(void)
        { int test,i;
                        for(i=0;i<strlen(ch);i++)
        if((ch[i]>=65&&ch[i]<=90)||(ch[i]>=97&&ch[i]<=122))
        test=0;
        else
{
        test=1;
        return test;
}
return test;
}




2-
a- Plain Text: “Engineering Excellence”
         Key: “Kulliyyah”

Encryption Using Playfair: FEMLEFMOMYMFIMGKKGMDE




Note: Sorry, this program not ready yet. It’s just admits the entered key text and mixes it with
the alphabets then it forms 5X5 matrix.



#include<stdio.h>
#include<string.h>
#include<iostream.h>
#include<stdlib.h>
#include<ctype.h>
#define w 999
void distributing_of_array(void);
void remove_of_repetation(void);
void removing_of_i_or_j(void);
void converting_to_5_by_5_matrix(void);
int chick(void);

char kt[w],ktd[w],mktd[w],matrix[5][5],ch[w];
main()
{
cout<<quot;Enter the Encryption key:>>PLEASE REMOVE THE SPACES:quot;<<endl;
  strcpy(ch,quot; quot;);
bb:
gets(kt);
strcpy(ch,kt);
if(chick()==1)
{cout<<quot;SORRY,ERROR IN THE INPUT DATA>>please RENTER just alphabetic key text without
spacesquot;<<endl;
goto bb;}



distributing_of_array();
puts(mktd);
removing_of_i_or_j();
converting_to_5_by_5_matrix();

}

void distributing_of_array()
{ int i;
char a[26];
//to ensure all enters are lower case letters
         for(i=0;i<strlen(kt);i++)
         kt[i]=tolower(kt[i]);

strcat(ktd,kt);

for(i=0;i<26;i++)
a[i]='a'+i;



strcat(ktd,a);

remove_of_repetation();



}




void remove_of_repetation(void)
                  {
        mktd[0]=ktd[0];
        int i,j,k=0,u,s=0;

            for(i=1;i<strlen(ktd);i++)
            {
                            s=0;
            for(j=0;j<k+1;j++)
                     if(ktd[i]==mktd[j])
                     s=1;
                                     if(s==0)
mktd[++k]=ktd[i];
                               }

                 }




               void removing_of_i_or_j(void)
               {
               int p1,p2,i,p;
               p1=0;
               p2=0;



                 for(i=0;i<strlen(mktd);i++)
                 {
                 if(mktd[i]=='i')
                 p1=i+1;
                 if(mktd[i]=='j')
                 p2=i+1;
                 }
                if((p1!=0)&&(p2!=0))
                {
                if(p1>p2)
       mktd[p1-1]='j';
       if(p2>p1)
       mktd[p2-1]='i';}

                for(i=0;i<26;i++)
                ktd[i]=mktd[i];

                remove_of_repetation();



       }

         //THIS FUNCTION COMBINE THE KEY TEXT WITH THE ALPHABETICS.
         //NOTE if you entered key text contains 'i' then the letter 'j' won't appear
         //and vica versa
  //again if you entered text contins i and j appeared respictively then j will be removed and vica
versa
 void converting_to_5_by_5_matrix(void)
 {
 int i,j,m=-1;
 for(i=0;i<5;i++)
for(j=0;j<5;j++)
matrix[i][j]=mktd[++m];

for(i=0;i<5;i++)
{printf(quot;nquot;);
for(j=0;j<5;j++)

printf(quot;%cquot;,matrix[i][j]);
 }

 }



  //Function chick, this function chicks the input data to make sure they are
//pure alphabetics and without spaces
        int chick(void)
        { int test,i;
                        for(i=0;i<strlen(ch);i++)
        if((ch[i]>=65&&ch[i]<=90)||(ch[i]>=97&&ch[i]<=122))
        test=0;
        else
        {
        test=1;
        return test;
}
return test;
}

More Related Content

What's hot

What's hot (19)

Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
 
Arrays
ArraysArrays
Arrays
 
Matlab assignment
Matlab assignmentMatlab assignment
Matlab assignment
 
Nonlinear analysis of braced frame with hinge by hinge method in c programming
Nonlinear analysis of braced frame with hinge by hinge method in c programmingNonlinear analysis of braced frame with hinge by hinge method in c programming
Nonlinear analysis of braced frame with hinge by hinge method in c programming
 
Monad
MonadMonad
Monad
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Geometric nonlinearity analysis of springs with rigid element displacement co...
Geometric nonlinearity analysis of springs with rigid element displacement co...Geometric nonlinearity analysis of springs with rigid element displacement co...
Geometric nonlinearity analysis of springs with rigid element displacement co...
 
Bartosz Milewski, “Re-discovering Monads in C++”
Bartosz Milewski, “Re-discovering Monads in C++”Bartosz Milewski, “Re-discovering Monads in C++”
Bartosz Milewski, “Re-discovering Monads in C++”
 
PRACTICAL COMPUTING
PRACTICAL COMPUTINGPRACTICAL COMPUTING
PRACTICAL COMPUTING
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”
 
C++ TUTORIAL 2
C++ TUTORIAL 2C++ TUTORIAL 2
C++ TUTORIAL 2
 
Bijender (1)
Bijender (1)Bijender (1)
Bijender (1)
 
Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output) Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)
 
Geometric and material nonlinearity analysis of 2 d truss with force and duct...
Geometric and material nonlinearity analysis of 2 d truss with force and duct...Geometric and material nonlinearity analysis of 2 d truss with force and duct...
Geometric and material nonlinearity analysis of 2 d truss with force and duct...
 
Introduction to Homomorphic Encryption
Introduction to Homomorphic EncryptionIntroduction to Homomorphic Encryption
Introduction to Homomorphic Encryption
 
Implementing stack
Implementing stackImplementing stack
Implementing stack
 
Oopppp
OoppppOopppp
Oopppp
 
Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...
Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...
Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...
 
Computing on Encrypted Data
Computing on Encrypted DataComputing on Encrypted Data
Computing on Encrypted Data
 

Viewers also liked (6)

ApresentaçãO1sapatosujos
ApresentaçãO1sapatosujosApresentaçãO1sapatosujos
ApresentaçãO1sapatosujos
 
Common Sense Design - MAS.671
Common Sense Design - MAS.671Common Sense Design - MAS.671
Common Sense Design - MAS.671
 
Meiosis
MeiosisMeiosis
Meiosis
 
Memorias De Un Feo
Memorias De Un FeoMemorias De Un Feo
Memorias De Un Feo
 
PocketWatchit - MAS.671
PocketWatchit - MAS.671PocketWatchit - MAS.671
PocketWatchit - MAS.671
 
Web2keynote
Web2keynoteWeb2keynote
Web2keynote
 

Similar to Microsoft Word Hw#1

C++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxC++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptx
ssuser3cbb4c
 
include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdf
contact32
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
shreeaadithyaacellso
 
Sorting programs
Sorting programsSorting programs
Sorting programs
Varun Garg
 

Similar to Microsoft Word Hw#1 (20)

C# Assignmet Help
C# Assignmet HelpC# Assignmet Help
C# Assignmet Help
 
include.docx
include.docxinclude.docx
include.docx
 
C program
C programC program
C program
 
Implementing string
Implementing stringImplementing string
Implementing string
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and Polynomial
 
C++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxC++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptx
 
Cpp programs
Cpp programsCpp programs
Cpp programs
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdf
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for Speed
 
oodp elab.pdf
oodp elab.pdfoodp elab.pdf
oodp elab.pdf
 
C Code and the Art of Obfuscation
C Code and the Art of ObfuscationC Code and the Art of Obfuscation
C Code and the Art of Obfuscation
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structures
 
Vcs16
Vcs16Vcs16
Vcs16
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
 
Stl algorithm-Basic types
Stl algorithm-Basic typesStl algorithm-Basic types
Stl algorithm-Basic types
 
C programs
C programsC programs
C programs
 
Sorting programs
Sorting programsSorting programs
Sorting programs
 

More from kkkseld (14)

H E A D S C A R F D E A D L O C K I N T U R K E Y A S A C A S E S T U D Y
H E A D S C A R F  D E A D L O C K  I N  T U R K E Y  A S  A  C A S E  S T U D YH E A D S C A R F  D E A D L O C K  I N  T U R K E Y  A S  A  C A S E  S T U D Y
H E A D S C A R F D E A D L O C K I N T U R K E Y A S A C A S E S T U D Y
 
Microsoft Word Mobile Multi Media Applications
Microsoft Word   Mobile Multi Media ApplicationsMicrosoft Word   Mobile Multi Media Applications
Microsoft Word Mobile Multi Media Applications
 
Microsoft Word Project, Firewalls
Microsoft Word   Project, FirewallsMicrosoft Word   Project, Firewalls
Microsoft Word Project, Firewalls
 
Microsoft Word Hw#2
Microsoft Word   Hw#2Microsoft Word   Hw#2
Microsoft Word Hw#2
 
Microsoft Word Hw#3
Microsoft Word   Hw#3Microsoft Word   Hw#3
Microsoft Word Hw#3
 
Asr
AsrAsr
Asr
 
Microsoft Word The Project, Islam And Science
Microsoft Word   The Project, Islam And ScienceMicrosoft Word   The Project, Islam And Science
Microsoft Word The Project, Islam And Science
 
Speech To Sign Language Interpreter System
Speech To Sign Language Interpreter SystemSpeech To Sign Language Interpreter System
Speech To Sign Language Interpreter System
 
Presentation, Firewalls
Presentation, FirewallsPresentation, Firewalls
Presentation, Firewalls
 
Sslis
SslisSslis
Sslis
 
Mobile Multi Media Applications
Mobile Multi Media ApplicationsMobile Multi Media Applications
Mobile Multi Media Applications
 
Presentation, Firewalls
Presentation, FirewallsPresentation, Firewalls
Presentation, Firewalls
 
Kerie2006 Poster Template 01
Kerie2006 Poster Template 01Kerie2006 Poster Template 01
Kerie2006 Poster Template 01
 
Asr
AsrAsr
Asr
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

Microsoft Word Hw#1

  • 1. Solutions to Assignment #1 ECE 6106 Computer NW Security By: Khalid El-Darymli Matric. No.: G0327887 ECE Dept. Faculty of Engineering URL: eng.iiu.edu.my International Islamic University Malaysia
  • 2. a- Plain Text: “engineering excellence” Encryption using Caesar’s cipher: HQJLQHHULQJ HAFHOOHQFH b- Program for problem # 1: //Program for problem# 1: #include<iostream.h> #include<string.h> #include<stdio.h> #define w 10000 #include<conio.h> char b[w]; int chick(void); void main() { void encrypt(void), decrypt(void); char op; cout<<quot;THIS PROGRAM CALCULATING THE ENCRYPTION OR DECRYPTION OF ENTERED STRINGquot;; cout<<quot; USING CAESAR's MOEHOD quot;<<endl; cout<<quot;|**********************************************************************|quot;<<endl; cout<<quot;Please Choose your CHOICEquot;<<endl; cout<<quot;To ENCRYPT PLEASE PREES E >>>>quot;<<endl; cout<<quot;To DECRYPT PLEASE PRESS D >>>quot;<<endl; cout<<quot;TO EXIT PLEASE PRESS any other keyquot;<<endl; cin>>op; clrscr(); switch(op) { case 'e':case 'E': encrypt();break; case 'd': case 'D': decrypt();break; default: break; } } /*THE FUNCTION OF ENCRYPTION */ void encrypt()
  • 3. { int i,s; char *p,c[w],n; cout<<quot;please enter the text to be encrypt:quot;<<endl; aa: gets(b); if(chick()==1) {cout<<quot;SORRY,ERROR IN THE INPUT DATA>>please RENTER the Ciphered text should be alphabetic text quot;<<endl; goto aa;} for(i=0;i<=strlen(b);i++) { s=0; p=&b[i]; if(*p==32||*p=='0') {s=1;n=32;} if(*p>=97&&*p<=119) {s=1,n=*p%97+68;} if(*p>=120&&*p<=122) {s=1,n=*p%120+65;} if(*p>=65&&*p<=87) {s=1,n=*p+3;} if(*p>=88&&*p<=90) {s=1,n=*p%88+65;} c[i]=n; if(s==0) {cout<<quot;YOU ENTERED NON-ALPHABETIC SYMBOL, ALL ENTERS SHOULD BE ALPHABETIC LETTERSquot;<<endl; goto xx;} } for(i=0;i<=strlen(b);i++) cout<<c[i]; xx: } //THE FUNCTION OF MAKING DECRYPTION void decrypt() { int i,s; char *p,c[w],n; cout<<quot;enter the text to be decryptquot;<<endl; aa: gets(b); if(chick()==1) {cout<<quot;SORRY,ERROR IN THE INPUT DATA>>please RENTER the Ciphered text should be alphabetic text quot;<<endl;
  • 4. goto aa;} for(i=0;i<=strlen(b);i++) { s=0; p=&b[i]; if(*p==32||*p=='0') {s=1;n=32;} if(*p>=100&&*p<=122) {s=1,n=*p-3;} if(*p>=97&&*p<=99) {s=1,n=120-*p%97;} if(*p>=68&&*p<=90) {s=1,n=*p%68+97;} if(*p>=65&&*p<=67) {s=1,n=120-*p%65;} c[i]=n; if(s==0) {cout<<quot;YOU ENTERED NON-ALPHABETIC SYMBOL, ALL ENTERS SHOULD BE ALPHABETIC LETTERSquot;<<endl; goto xx;} } for(i=0;i<=strlen(b);i++) cout<<c[i]; xx: } //Function chick, this function chicks the input data to make sure THAT they are //pure alphabetics WITH OR WITHOUT SPACES int chick(void) { int test,i; for(i=0;i<strlen(b);i++) if((b[i]>=65&&b[i]<=90)||(b[i]>=97&&b[i]<=122)||(b[i]==32)) test=0; else { test=1; return test; } return test; }
  • 5. 3-Program for problem # 3: //Program for problem# 3: #include<stdio.h> #include<stdlib.h> #include<string.h> #include<iostream.h> #include<conio.h> #include<ctype.h> #define w 10000 char pt[w],kt[w],ct[w],ch[w]; char vignere_table_cipher(char,char); char vignere_table_decipher(char,char); int chick(void); void main(){ char op; void cipher(void); void decipher(void); cout<<quot;THIS PROGRAM PERFORMS ENCRYPTION OR DECRYPTION FOR ENTERED TEXT usingquot;; cout<<quot;Vigenere's autokey cipherquot;<<endl<<endl; cout<<quot;|**********************************************************************|quot;<<endl; cout<<quot;Please Choose your CHOICEquot;<<endl; cout<<quot;[E] For ENCRYPTION please <<Press E followed by enter quot;<<endl; cout<<quot;[D] For DECRYPTION please <<PRESS D followed by enterquot;<<endl; cout<<quot; For EXIT please press any other key followed by enterquot;<<endl; cin>>op; switch(op) { case 'e': case 'E':cipher();break; case 'd': case 'D':decipher();break; default: break; }} //Ciphering function: This function performs encryption void cipher(void) { int x,n,i; char mkt[w],ct[w]; char *pp,*kp; clrscr(); cout<<quot;Enter the text to be Encrypt:>>PLEASE REMOVE SPACES:quot;<<endl; aa: gets(pt); strcpy(ch,pt); if(chick()==1)
  • 6. {cout<<quot;SORRY,ERROR IN THE INPUT DATA>>please RENTER just alphabetic text without spacesquot;<<endl; goto aa;} cout<<quot;Enter the Encryption key:>>PLEASE REMOVE THE SPACES:quot;<<endl; strcpy(ch,quot; quot;); bb: gets(kt); strcpy(ch,kt); if(chick()==1) {cout<<quot;SORRY,ERROR IN THE INPUT DATA>>please RENTER just alphabetic text without spacesquot;<<endl; goto bb;} for (i=0; i<strlen(pt); i++) pt[i] = tolower(pt[i]); for(i=0;i<strlen(kt);i++) kt[i]=tolower(kt[i]); //Making the length of key equal to the length of plain text x=strlen(pt); xx: x-=strlen(kt); if(x>=0) {n=strlen(kt); strncat(mkt,kt,n); goto xx; } else strncat(mkt,kt,x+strlen(kt)); // end of process //Ciphering and printing of the plaintext for(i=0;i<strlen(pt);i++) { pp=&pt[i]; kp=&mkt[i]; ct[i]=vignere_table_cipher(*pp,*kp); } printf(quot;nquot;); for(i=0;i<strlen(ct);i++) ct[i]=toupper(ct[i]); puts(ct); } //End of process //This function calculating the character corresponding to that we obtain fro Vignere Table //for two submitted character, the key character and the plain text text character
  • 7. //the function returns the ciphered character char vignere_table_cipher(char k,char p) { char c; int d,comp; comp=k-'a'; d=p+comp; if(d>122) {d%=122; d+=96;} c=d; return c; } //Function decipher, this function perofoms decryption. void decipher(void) { int x,n,i; char mkt[w],dt[w]; char *pp,*kp,rvv; clrscr(); cout<<quot;Enter the text to be DECRYPT:>>PLEASE remove the spaces>>quot;<<endl; aa: gets(ct); strcpy(ch,ct); if(chick()==1) {cout<<quot;SORRY,ERROR IN THE INPUT DATA>>please RENTER the Ciphered text just alphabetic text without spacesquot;<<endl; goto aa;} strcpy(ch,quot; quot;); cout<<quot;Enter the DECRYPTION key:>>PLEASE REMOVE THE SPACES>>quot;<<endl; bb: gets(kt); strcpy(ch,kt); if(chick()==1) {cout<<quot;SORRY,ERROR IN THE INPUT DATA>>please RENTER the KEY just as alphabetic text without spacesquot;<<endl; goto bb;} for (i=0; i<strlen(ct); i++) ct[i] = tolower(ct[i]); for(i=0;i<strlen(kt);i++) kt[i]=tolower(kt[i]); //Making the length of key equal to the length of cipheered text x=strlen(ct); xx:
  • 8. x-=strlen(kt); if(x>=0) {n=strlen(kt); strncat(mkt,kt,n); goto xx; } else strncat(mkt,kt,x+strlen(kt)); // end of process //deCiphering and printing of the plaintext for(i=0;i<strlen(ct);i++) { pp=&ct[i]; kp=&mkt[i]; dt[i]=vignere_table_decipher(*kp,*pp); } printf(quot;nquot;); puts(dt); } //End of process //This function calculating the character corresponding to that we obtain from Vignere Table //for two submitted character, the key character and the ciphered text character //the function returns the plain text character char vignere_table_decipher(char kt,char ct) { char d; int comp,pt; comp=kt-'a'; pt=ct-comp; if(pt<97) pt+=123-97; d=pt; return d; } //End of function //Function chick, this function chicks the input data to make sure they are //pure alphabetics and without spaces int chick(void) { int test,i; for(i=0;i<strlen(ch);i++) if((ch[i]>=65&&ch[i]<=90)||(ch[i]>=97&&ch[i]<=122)) test=0; else
  • 9. { test=1; return test; } return test; } 2- a- Plain Text: “Engineering Excellence” Key: “Kulliyyah” Encryption Using Playfair: FEMLEFMOMYMFIMGKKGMDE Note: Sorry, this program not ready yet. It’s just admits the entered key text and mixes it with the alphabets then it forms 5X5 matrix. #include<stdio.h> #include<string.h> #include<iostream.h> #include<stdlib.h> #include<ctype.h> #define w 999 void distributing_of_array(void); void remove_of_repetation(void); void removing_of_i_or_j(void); void converting_to_5_by_5_matrix(void); int chick(void); char kt[w],ktd[w],mktd[w],matrix[5][5],ch[w]; main() { cout<<quot;Enter the Encryption key:>>PLEASE REMOVE THE SPACES:quot;<<endl; strcpy(ch,quot; quot;); bb: gets(kt); strcpy(ch,kt); if(chick()==1) {cout<<quot;SORRY,ERROR IN THE INPUT DATA>>please RENTER just alphabetic key text without spacesquot;<<endl;
  • 10. goto bb;} distributing_of_array(); puts(mktd); removing_of_i_or_j(); converting_to_5_by_5_matrix(); } void distributing_of_array() { int i; char a[26]; //to ensure all enters are lower case letters for(i=0;i<strlen(kt);i++) kt[i]=tolower(kt[i]); strcat(ktd,kt); for(i=0;i<26;i++) a[i]='a'+i; strcat(ktd,a); remove_of_repetation(); } void remove_of_repetation(void) { mktd[0]=ktd[0]; int i,j,k=0,u,s=0; for(i=1;i<strlen(ktd);i++) { s=0; for(j=0;j<k+1;j++) if(ktd[i]==mktd[j]) s=1; if(s==0)
  • 11. mktd[++k]=ktd[i]; } } void removing_of_i_or_j(void) { int p1,p2,i,p; p1=0; p2=0; for(i=0;i<strlen(mktd);i++) { if(mktd[i]=='i') p1=i+1; if(mktd[i]=='j') p2=i+1; } if((p1!=0)&&(p2!=0)) { if(p1>p2) mktd[p1-1]='j'; if(p2>p1) mktd[p2-1]='i';} for(i=0;i<26;i++) ktd[i]=mktd[i]; remove_of_repetation(); } //THIS FUNCTION COMBINE THE KEY TEXT WITH THE ALPHABETICS. //NOTE if you entered key text contains 'i' then the letter 'j' won't appear //and vica versa //again if you entered text contins i and j appeared respictively then j will be removed and vica versa void converting_to_5_by_5_matrix(void) { int i,j,m=-1; for(i=0;i<5;i++)
  • 12. for(j=0;j<5;j++) matrix[i][j]=mktd[++m]; for(i=0;i<5;i++) {printf(quot;nquot;); for(j=0;j<5;j++) printf(quot;%cquot;,matrix[i][j]); } } //Function chick, this function chicks the input data to make sure they are //pure alphabetics and without spaces int chick(void) { int test,i; for(i=0;i<strlen(ch);i++) if((ch[i]>=65&&ch[i]<=90)||(ch[i]>=97&&ch[i]<=122)) test=0; else { test=1; return test; } return test; }