-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVIGENEREimplement.cpp
More file actions
65 lines (53 loc) · 1.23 KB
/
VIGENEREimplement.cpp
File metadata and controls
65 lines (53 loc) · 1.23 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "VIGENEREimplement.h"
#include <algorithm>
// This function generates the key in
// a cyclic manner until it's length isi'nt
// equal to the length of original text
//creates cyclic key
std::string generateKey(std::string str, std::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;
}
// This function returns the encrypted text
// generated with the help of the key
std::string cipherText(std::string str, std::string key)
{
std::string cipher_text;
for (int i = 0; i < str.size(); i++)
{
// converting in range 0-25
char x = (str[i] + key[i]) % 26;
// convert into alphabets(ASCII)
x += 'A';
cipher_text.push_back(x);
}
return cipher_text;
}
// This function decrypts the encrypted text
// and returns the original text
std::string originalText(std::string cipher_text, std::string key)
{
std::string orig_text;
for (int i = 0; i < cipher_text.size(); i++)
{
// converting in range 0-25
char x = (cipher_text[i] - key[i] + 26) % 26;
// convert into alphabets(ASCII)
x += 'A';
orig_text.push_back(x);
}
return orig_text;
}
std::string probe(std::string str)
{
return "hi";
}