Q:

encryption from char to int

i'am writing some encryption program in c++, and when i start it then console print only one char, and decryption don't work, when i do encryption / decryption then program not doing that with numeric numbers of nn, he do that with hes adress. sorry for my english.
// Var
std::string text = "string";
const char *nn = text.c_str();

// Encryption
int x = (int(nn));
x = x * 3 - 100 * 2;
cout << "Numerical numbers: " << x << endl;
cout << "String: " << (char(x)) << endl;

// Decryption
x = (x - 100 * 2) / 3;
cout << "Numerical numbers: " << x << endl;
cout << "String: " << (char(x));

A:

Unless you have restrictions that you have to use the formula x * 3 - 100 * 2 for encryption/decryption, I suggest you to use XOR.
#include <iostream>
#include <string>

int main()
{
    // Var
    std::string text = "string", encrypt, decrypt;
    
    // Encryption
    for (int i = 0; i < text.length(); i++)
    {
        encrypt += text[i] ^ '1';
    }

    // Decryption
    for (int i = 0; i < encrypt.length(); i++)
    {
        decrypt += encrypt[i] ^ '1';
    }
    
    std::cout << "original text: " << text << std::endl << "encrypted text: " << encrypt << std::endl << "decrypted text: " << decrypt;
} 

The output of the above code would be:

original text: string
encrypted text: BECX_V
decrypted text: string

Here is an working example of the above code.

