Thursday, April 9, 2015

Vigenere Cipher C++ code

Code
/*
Vigenere Cipher C++ code
Here we assume that plain text length is equal or  more than key length
*/

#include<iostream>
#include<string.h>

using namespace std;

class VigenereCipher
{
char plain[33],cipher[33],key[11];
int i,j,pl,kl;
public:
VigenereCipher(){ }
void GetPlain()
{
cout<<"\t\t\t ***ENTER PLAIN TEXT***"<<endl;
cin>>plain;
pl=strlen(plain);
}
void GetKey()
{
cout<<endl<<"\t\t\t ***ENTER KEY***"<<endl;
cin>>key;
kl=strlen(key);
}
void KeyManip()
{
for(i=0;i<pl;i++)
{
key[i]=key[i%kl];
}
}
void Encryption()
{
for(i=0;i<pl;i++)
{
cipher[i]=(((plain[i]-97)+(key[i]-97))%26)+97;
}
}
void DisplayCipher()
{
cout<<endl<<"\t\t\t ***CIPHER TEXT IS***"<<endl;
for(j=0;j<pl;j++)
{
cout<<cipher[j];
}
cout<<endl<<endl<<"\t\t\t+++END OF PROGRAM+++";
}
};

int main()
{
VigenereCipher v1;
v1.GetPlain();
v1.GetKey();
v1.KeyManip();
v1.Encryption();
v1.DisplayCipher();
return 0;
}

7 comments:

  1. Can you explain this line?
    "cipher[i]=(((plain[i]-97)+(key[i]-97))%26)+97;"
    I don't understand how it works.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  4. Hi Glenn Jamero!! :) You're so cutie'pooot 8====D I like to suck your small dick. Shut the fuck up ./. I'm the real founder of the Company of Anonymouse from China!!!!! Fuck you. Insert- PHILIPPINES is the best and unbreakable hackers in the world and also universe.

    ReplyDelete