forked from HarshCasper/NeoAlgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vigenere_Cipher.cpp
42 lines (36 loc) · 1.06 KB
/
Vigenere_Cipher.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*Vigenere Cipher Algorithm is a famous cryptographic algorithm.
Vigenère cipher is a method of encrypting alphabetic text by using a series of interwoven Caesar ciphers*/
#include <bits/stdc++.h>
using namespace std;
string key="NEOALGO";
int x=key.size();
string encryption(string message) {
string cipher;
for (int i = 0; i < message.size(); ++i) {
int t=(message[i] + key[i%x])%26;
cipher+=('A'+t);
}
return cipher;
}
string decryption(string cipher) {
string message;
for (int i = 0; i < cipher.size(); ++i) {
int t=(cipher[i] - key[i%x] +26)%26;
message+=('A'+t);
}
return message;
}
int main() {
string message = "TESSERACTCODINGNEOALGO";
//use only uppercase characters (you can modify the code for lowercase characters)
string new_message = encryption(message);
cout << "Encrypted Message: " << new_message << "\n";
string original_message = decryption(new_message);
cout << "Decrypted Message: " << original_message;
return 0;
}
/*
OUTPUT:
Encrypted Message: GIGSPXOPXQOOOBTRSOLRUB
Decrypted Message: TESSERACTCODINGNEOALGO
*/