The question doesn't make much sense as it stands.
A pointer will point to a block of memory, and you probably want to encrypt the block that is pointed to, not the pointer itself. You'll also need to know the size of the block.
Once you have the data to be encrypted, then you can apply one of the many encryption algorithms.
the problem is easy enough. you can do the same with <random> and a little more code to set that up.
1 2 3 4 5 6 7 8 9
int password = 1234; //get any string from user, convert to int somehow if you want to get fancy.
int x;
int * ip = &x;
srand(password);
uint64_t enc = (uint64_t)(ip)^rand();
file << enc;
decrypt:
srand(password);
ip = (int*)(enc^rand());
but pointers don't survive across executions. if you save a number to a file, exit the program, restart the program, load the pointer, and try to use it, it will NOT be a valid pointer most of the time. It could work on a fully deterministic embedded system with a very simple OS and a very regimented program execution cycle such that your program always loaded to the same memory each time, but generally speaking, this is nonsense.
Thanks for reply jonnin
your example is working , my program auto get game pointer and get other info and save it in ini file ,This information is used by another program , I just don't want anyone to read what's inside the file ,That's why I wanted to encrypt the pointer
Glad it helps. Fair warning that xor encrypts are easy to hack if someone gets serious about breaking in, esp if its just off the same constant each time.
The fact that you're storing the pointer in an INI file suggests that you want to read it the next time you run the program. Or that you want to read it from another program. Neither one of those things will work.
When you run a program and it puts an object at address X, there's no guarantee that it will put the object at that same address the next time it runs. Chances are pretty slim in fact. If you modify the program and recompile it, chances drop from slim to preposterously low.
If you want to read that pointer into another program, you need to be aware that the other program can't access that address and get the same data, at least not on most computers. Programs run in different "address spaces." This is to protect them from each other.
As Gando said, this is an XY problem. You're asking about a proposed solution to your problem rather than describing the problem itself. Whatever you're trying to accomplish, there's probably a better way to do it.