-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencrypt.cpp
More file actions
43 lines (32 loc) · 1.22 KB
/
Copy pathencrypt.cpp
File metadata and controls
43 lines (32 loc) · 1.22 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
#include "encrypt.hpp"
//Add salting+hashing
//Have it spit out garbage/no data if secret is wrong. Have processing time be as equivalent as possible.
std::string viginere_encrypt(std::string secret, std::string password){
//Version of the viginere cipher - doesn't loop back around to characters. Generalised for any ascii symbol.
std::string key = "";
std::string encryptedSecret = "";
//make key length equal to secret length
while(key.length() < secret.length()){
key+=password;
}
key = key.substr(0,secret.length());
//Add ascii value of key[i] to secret[i] for encryptedSecret[i]
for(int i=0;i<key.length();i++){
encryptedSecret+= secret[i] + key[i];
}
return encryptedSecret;
}
std::string viginere_decrypt(std::string secret, std::string password){
std::string key = "";
std::string decryptedSecret = "";
//make key length equal to secret length
while(key.length() < secret.length()){
key+=password;
}
key = key.substr(0,secret.length());
//Add ascii value of key[i] to secret[i] for encryptedSecret[i]
for(int i=0;i<key.length();i++){
decryptedSecret+= secret[i] - key[i];
}
return decryptedSecret;
}