Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

// Example program

#include <iostream>

#include <string>

using namespace std;

int main()

string plainText;

string cipherText;

string key;

cout << "Enter plaintext: ";

getline(cin, plainText);

cout << endl;

cout << "Enter key: ";

getline(cin, key);

int j = 0;

for (int i = 0; i<plainText.length(); i++)

////// if start

if(plainText[i]>='a' && plainText[i] <='z') // if(islower isupper(plainText[i])) //to check upper case

cipherText[i]=(((plainText[i]-97)+(key[j % key.length()]-97)) % 26)+97;

else if (plainText[i] >= 'A' && plainText[i] <= 'Z') // if(islower(plainText[i])) //to check lower case

cipherText[i]=(((plainText[i]-65)+(key[j% key.length()]-65)) % 26)+ 65;

j++;

cout << endl << "ciphertext: ";

for (int i = 0; i< plainText.length(); i++)

cout << cipherText[i];

cout << endl;

system("pause");

return 0;

You might also like