From 560011163f1f611aa44bd73736f31d973aa4f527 Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Fri, 9 Oct 2020 17:46:12 +0530 Subject: [PATCH] Create Vigener_cipher.cpp --- Vigener_cipher.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 Vigener_cipher.cpp 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; +}