Important Ciphers
Important Ciphers
Important Ciphers
This type of cipher is not as strong but due to the variable distances between consecutive letters of the
plain text when encrypted in the cipher text it is relatably reliable. But if we brute force all no. of rows
the plain text can be obtained as length is same.
#include <bits/stdc++.h>
using namespace std;
rail[row][col++] = text[i];
dir_down?row++ : row--;
}
string result;
for (int i=0; i < key; i++)
for (int j=0; j < text.length(); j++)
if (rail[i][j]!='\n')
result.push_back(rail[i][j]);
return result;
}
int main()
{
cout << encryptRailFence("ttyl", 2) << endl;
return 0;
}
#include<stdio.h>
#include<string.h>
#include<ctype.h>
main()
{
int i,j,len1,len2,numstr[100],numkey[100],numcipher[100];
char str[100],key[100],cipher[100];
printf("Enter a string text to encrypt\n");
gets(str);
for(i=0,j=0;i<strlen(str);i++)
{
if(str[i]!=' ')
{
str[j]=toupper(str[i]);
j++;
}
}
str[j]='\0';
for(i=0;i<strlen(str);i++)
{
numstr[i]=str[i]-'A';
}
printf("Enter key string of random text\n");
gets(key);
for(i=0,j=0;i<strlen(key);i++)
{
if(key[i]!=' ')
{
key[j]=toupper(key[i]);
j++;
}
}
key[j]='\0';
for(i=0;i<strlen(key);i++)
{
numkey[i]=key[i]-'A';
}
for(i=0;i<strlen(str);i++)
{
numcipher[i]=numstr[i]+numkey[i];
}
for(i=0;i<strlen(str);i++)
{
if(numcipher[i]>25)
{
numcipher[i]=numcipher[i]-26;
}
}
printf("One Time Pad Cipher text is\n");
for(i=0;i<strlen(str);i++)
{
printf("%c",(numcipher[i]+'A'));
}
printf("\n");
}
Vigenère cipher (polyalphabetic substitution)
The Vigenère cipher is a method of encrypting messages by using a series of different Caesar ciphers
based on the letters of a particular keyword. The Vigenère cipher is more powerful than a single Caesar
cipher and is much harder to crack.
#include<bits/stdc++.h>
string cipher_text;
x += 'A';
cipher_text.push_back(x);
return cipher_text;
string orig_text;
{
int x = (cipher_text[i] - key[i] + 26 + 32) %26;
x += 'a';
orig_text.push_back(x);
return orig_text;
int main()
return 0;
}
Hill Cipher
The Hill cipher is a classical symmetric encryption algorithm that succumbs to the know-
plaintext attack. Although its vulnerability to cryptanalysis has rendered it unusable in practice, it
still serves an important pedagogical role in cryptology and linear algebra.
#include <iostream>
int keyMatrix[][3],
int messageVector[][1])
int x, i, j;
cipherMatrix[i][j] = 0;
for (x = 0; x < 3; x++)
cipherMatrix[i][j] +=
keyMatrix[i][x] * messageVector[x][j];
int messageVector[3][1];
int cipherMatrix[3][1];
string CipherText;
}
int main()
{21,18,21},
{2, 2, 19} };
cout<<"Key is :"<<endl;
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
cout<<key[i][j]<<" ";
cout<<endl;
cout<<endl;
HillCipher(plaintext, key);
return 0;
}
Caeser Cipher
It is considered a weak method of cryptography, as it is easy to decode the message owing to its
minimum security techniques.
#include<bits/stdc++.h>
int main()
int key = 3;
char a[100];
for(int i=0;i<26;i++)
cin>>a[i];
vector<char>v;
char ch;
for(int i=0;i<26;i++)
{
ch = a[i] - 32 + 3;
if(ch>90)
ch = ch-26;
v.push_back(ch);
` int n = v.size();
cout<<v[i];
Transpositional Cipher
#include<bits/stdc++.h>
int main()
vector<int>v1,v2;
int n;
for(int i=0;i<n;i++)
int e;
cin>>e;
v1.push_back(e);
v2.push_back(e);
int rows;
cin>>rows;
cout<<endl;
char a[rows][n];
for(int i=0;i<rows;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];
for(int i=0;i<rows;i++)
for(int j=0;j<n;j++)
cout<<a[i][j]<<" ";
}
cout<<endl;
cout<<endl;
int s = v1.size();
int cnt = 0;
while(cnt < s)
for(int i=0;i<rows;i++)
cout<<a[i][index]<<" ";
v1[index] = INT_MAX;
cnt++;
// v1.erase(find(v1.begin(),v1.end(),e));
//s = v1.size();
//cout<<endl;
return 0;