Encryption program

So I was messing around with xor encryption and I spent a while trying to get this thing encrypted pretty decently and well I am wondering if you could see any improvements to it.
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
#include <iostream>
#include <string>
#include <random>
#include <chrono>
using namespace std;
template<typename data_encrypt> 
class encryption {
private:
    data_encrypt encrypted;
    mutable char key;
    mutable char random_keys[5];
    bool encryption;
public:
    void change_key_values () const {
        auto seed = (std::chrono::system_clock::now().time_since_epoch().count());
        std::mt19937 engine(seed);
        std::uniform_int_distribution<int> retrieve_key(1, 99);
        key = retrieve_key(engine);
        for (int i = 0; i < 5; i++) {
            random_keys[i] = retrieve_key(engine);
        }
    }
    void encrypt(data_encrypt value) {
        encrypted = value;
        change_key_values();
        for (int index = 5; index != (encrypted.size() + 5); index++) {
            encrypted[index - 5] ^= key + (random_keys[index % 5] & 10) + (index & 3); //Addition part does nothing sometimes whilst doing things other times
        }
        encryption = true;
    }
    data_encrypt message() const {
        return encrypted;
    }
    data_encrypt de_crypt() const {
        string temp = encrypted;
        for (int index = 5; index != (temp.size() + 5); index++) {
            temp[index - 5] ^= key + (random_keys[index % 5] & 10) + (index & 3);
            
        }
        return temp;
    }
};
int main()
{
    string value;
    cout << "Enter in a string to encrypt: ";
    getline(cin, value);
    encryption<string> device;
    device.encrypt(value);
    cout << "\nEncrypted message: ";
    cout << device.message();
    cout << "\nDecrypted message: ";
    cout << device.de_crypt();
}
Last edited on
Topic archived. No new replies allowed.