SlideShare a Scribd company logo
1 of 5
PlayFair Cipher Code by Khawar:
#include <iostream>
usingnamespace std;
intmain()
{
inti,j,x,r,n,z,c1,c2,p;c1=0;
char a2[25]={'a','b','c','d','e','f','g','h','i','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char key[50],aa[100];
cout<<"write yourcyphertextheren";
cin.getline(aa,100);
cout<<"enteryourkeyheren";
cin.getline(key,50);
intll=strlen(key);
char a[5][5];
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
c2=0;
if(c1<ll)
{
for(p=0;p<25;p++)
{
if(key[c1]==a2[p])
{
a[i][j]=key[c1];
c1++;c2=1; a2[p]='1';break;
}
if(p==24&&c2!=1)
{
p=0;c1++;
}
}
}
else
{
for(p=0;p<25;p++)
{
if(a2[p]!='1')
{
a[i][j]=a2[p];a2[p]='1';break;
}
}
}
}
}
cout<<"n";
intl=strlen(aa);
intro1,co1,ro2,co2;
x=0;
while(x<l)
{
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(aa[x]==a[i][j]){ro1=i;co1=j;}
if(aa[x+1]==a[i][j]){ro2=i;co2=j;}
}
}
if(ro1==ro2)
{
if(co1>0)
{
aa[x]=a[ro1][co1-1];
}
if(co2>0)
{
aa[x+1]=a[ro2][co2-1];
}
if(co1==0)
{
aa[x]=a[ro1][4];
}
if(co2==0)
{
aa[x+1]=a[ro2][4];
}
}
else if(co1==co2)
{
if(ro1>0)
{
aa[x]=a[ro1-1][co1];
}
if(ro2>0)
{
aa[x+1]=a[ro2-1][co2];
}
if(ro1==0)
{
aa[x]=a[4][co1];
}
if(ro2==0)
{
aa[x+1]=a[4][co2];
}
}
else
{
aa[x]=a[ro1][co2];
aa[x+1]=a[ro2][co1];
}
x=x+2;
}
cout<<"plantextis= "<<aa<<"n";
}
Thanks:

More Related Content

What's hot

CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsKrishnan MuthuManickam
 
Network lap pgms 7th semester
Network lap pgms 7th semesterNetwork lap pgms 7th semester
Network lap pgms 7th semesterDOSONKA Group
 
Code Optimization
Code OptimizationCode Optimization
Code Optimizationguest9f8315
 
Travelling salesman dynamic programming
Travelling salesman dynamic programmingTravelling salesman dynamic programming
Travelling salesman dynamic programmingmaharajdey
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingMuthu Vinayagam
 
LALR Parser Presentation ppt
LALR Parser Presentation pptLALR Parser Presentation ppt
LALR Parser Presentation pptWPVKP.COM
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and boundAbhishek Singh
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generationVipul Naik
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsMohamed Loey
 
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)Dhrumil Panchal
 
R Programming language model test paper
R Programming language model test paperR Programming language model test paper
R Programming language model test paperLuckshay Batra
 
Introduction of cryptography and network security
Introduction of cryptography and network securityIntroduction of cryptography and network security
Introduction of cryptography and network securityNEHA PATEL
 

What's hot (20)

CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of Algorithms
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
And or search
And or searchAnd or search
And or search
 
Network lap pgms 7th semester
Network lap pgms 7th semesterNetwork lap pgms 7th semester
Network lap pgms 7th semester
 
OSI Security Architecture
OSI Security ArchitectureOSI Security Architecture
OSI Security Architecture
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Travelling salesman dynamic programming
Travelling salesman dynamic programmingTravelling salesman dynamic programming
Travelling salesman dynamic programming
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python Programming
 
LALR Parser Presentation ppt
LALR Parser Presentation pptLALR Parser Presentation ppt
LALR Parser Presentation ppt
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and bound
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph Algorithms
 
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
 
3. cs8451 daa anna univ question bank unit 3
3. cs8451 daa anna univ question bank unit 33. cs8451 daa anna univ question bank unit 3
3. cs8451 daa anna univ question bank unit 3
 
R Programming language model test paper
R Programming language model test paperR Programming language model test paper
R Programming language model test paper
 
Tic tac toe simple ai game
Tic tac toe simple ai gameTic tac toe simple ai game
Tic tac toe simple ai game
 
Arrays
ArraysArrays
Arrays
 
Query trees
Query treesQuery trees
Query trees
 
Introduction of cryptography and network security
Introduction of cryptography and network securityIntroduction of cryptography and network security
Introduction of cryptography and network security
 

Viewers also liked

Cipher techniques
Cipher techniquesCipher techniques
Cipher techniquesMohd Arif
 
Ciphers and codes
Ciphers and codesCiphers and codes
Ciphers and codesTedi Thug
 
Lan technologies
Lan technologiesLan technologies
Lan technologiesOnline
 
Data Encryption Standard (DES)
Data Encryption Standard (DES)Data Encryption Standard (DES)
Data Encryption Standard (DES)Haris Ahmed
 
key distribution in network security
key distribution in network securitykey distribution in network security
key distribution in network securitybabak danyal
 
Network Hardware And Software
Network Hardware And SoftwareNetwork Hardware And Software
Network Hardware And SoftwareSteven Cahill
 

Viewers also liked (11)

Cipher techniques
Cipher techniquesCipher techniques
Cipher techniques
 
Ciphers and codes
Ciphers and codesCiphers and codes
Ciphers and codes
 
Ch02...1
Ch02...1Ch02...1
Ch02...1
 
Lan technologies
Lan technologiesLan technologies
Lan technologies
 
Data Encryption Standard (DES)
Data Encryption Standard (DES)Data Encryption Standard (DES)
Data Encryption Standard (DES)
 
Data encryption standard
Data encryption standardData encryption standard
Data encryption standard
 
key distribution in network security
key distribution in network securitykey distribution in network security
key distribution in network security
 
Ethernet technology
Ethernet technologyEthernet technology
Ethernet technology
 
DES
DESDES
DES
 
Network topology.ppt
Network topology.pptNetwork topology.ppt
Network topology.ppt
 
Network Hardware And Software
Network Hardware And SoftwareNetwork Hardware And Software
Network Hardware And Software