diff --git a/Vigener_cipher.cpp b/Vigener_cipher.cpp new file mode 100644 index 0000000..0a6bb99 --- /dev/null +++ b/Vigener_cipher.cpp @@ -0,0 +1,80 @@ +#include +using namespace std; + +string generateKey(string str, string key) +{ + int x = str.size(); + for (int i = 0; ; i++) + { + if (x == i) + i = 0; + if (key.size() == str.size()) + break; + key.push_back(key[i]); + } + return key; +} + +string encrypt(string str, string key) +{ + string cipher_text; + + for (int i = 0; i < str.size(); i++) + { + char x = (((str[i] + key[i]) %26) + 65); + cipher_text.push_back(x); + } + return cipher_text; +} + +string decrypt(string cipher_text, string key) +{ + string orig_text; + + for (int i = 0 ; i < cipher_text.size(); i++) + { + char x = (((cipher_text[i] - key[i] + 26) %26) +65); + orig_text.push_back(x); + } + return orig_text; +} + +int main() +{ + + string text="", keyword="", key=""; + int sel=0; + char ch='y'; + cout<<"===VIGENERE CIPHER==="<>sel; + switch(sel) { + case 1: + cout << "Enter the text : "; + cin.ignore(); + getline(cin,text); + cout<< "Enter the key: "; + getline(cin,keyword); + key = generateKey(text,keyword); + cout << "Encrypted Text is(Cipher Text) : " << encrypt(text,key) <>ch; + }while(ch!='n'); + return 0; +}