Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › Programming › C++/C Programming › Encrypter- I need help

Encrypter- I need help

Posts 1–15 of 19 · Page 1 of 2
why06
why06
Encrypter- I need help
Ok. I'm posting this mainly because of just an utter lack of topics in the C++ forum and zeco is about to go crazy from boredom xD, and also because after much trial and error I still can't quite get my XOR encrypter to work.

What it's supposed to do:
1. Take a Message
2. Take a key
3. Encrypt the message with the key
4. Print out the Encrypted message.

Problem:
My problem is that you can't copy and paste the message back in the gui. the console window just doesnt allow you to paste. D: I need a way people can paste the code back in the gui. I need for the program to read the message from a .txt file so I can easily edit (copy and paste) messages


I was planing to release it as a little present so we could send encrypted messages to each other :P. Guess I'll just have to release it half finished.
Code:
#include <iostream>
using namespace std;

int main()
{
    char key;
    char str[9000];
    cout << "Enter the message you want to encrypt: "<<endl;
    cin >> str;
    cout << "Enter your encryption key(any character): ";
    cin >> key;
     for(int i = 0;str[i]; i++)
     {
             str[i] = str[i] ^ key;
     }
    cout << "\nHere is your encrypted message: \n" << str << endl << "\n use key of: " << key << " to decode.\n";
    system("pause");
    return 0;
}
Here's the source code for the Encrypter and the Encrypt.exe:
#1 · edited 17y ago · 17y ago
ZE
zeco
Quote Originally Posted by why06 View Post
Ok. I'm posting this mainly because of just an utter lack of topics in the C++ forum and zeco is about to go crazy from boredom xD, and also because after much trial and error I still can't quite get my XOR encrypter to work.

What it's supposed to do:
1. Take a Message
2. Take a key
3. Encrypt the message with the key
4. Print out the Encrypted message.

Problem:
My problem is that you can't copy and paste the message back in the gui. the console window just doesnt allow you to paste. D: I need a way people can paste the code back in the gui. I need for the program to read the message from a .txt file so I can easily edit (copy and paste) messages


I was planing to release it as a little present so we could send encrypted messages to each other :P. Guess I'll just have to release it half finished.
Code:
#include <iostream>
using namespace std;

int main()
{
    char key;
    char str[9000];
    cout << "Enter the message you want to encrypt: "<<endl;
    cin >> str;
    cout << "Enter your encryption key(any character): ";
    cin >> key;
     for(int i = 0;str[i]; i++)
     {
             str[i] = str[i] ^ key;
     }
    cout << "\nHere is your encrypted message: \n" << str << endl << "\n use key of: " << key << " to decode.\n";
    system("pause");
    return 0;
}
Here's the source code for the Encrypter and the Encrypt.exe:
MUWAHHAHA Brilliant, I remember vaguely of a class in iostream or something to do that. Give me half an hour to play with this.

edit: Ok they are in ifstream, and of stream. I'm probably going to edit as i go along.
edit: Ok first change i made to your program is i changed the char array to string cause that's easier for me.
#2 · edited 17y ago · 17y ago
why06
why06
Quote Originally Posted by zeco View Post
MUWAHHAHA Brilliant, I remember vaguely of a class in iostream or something to do that. Give me half an hour to play with this.

edit: Ok they are in ifstream, and of stream. I'm probably going to edit as i go along.
You can have all the time you want :P Just tell me when you figure it out.
#3 · 17y ago
ZE
zeco
Quote Originally Posted by why06 View Post
You can have all the time you want :P Just tell me when you figure it out.
Okies, =D
(>_>, trop court.)
#4 · 17y ago
ZE
zeco
Oh by the way, in your encryption loop. How exactly does the bitwise xor operator work? I know of it. I just don't know exactly about it. But yeah i need you to right a decryption loops i guess?

I think everything pretty much works so far, well i guess i will provide a change log of sorts.

*The program now outputs the encryption to a text file in the same folder as the EXE.
*It also has a extremely basic front menu
*The program can also now read an encryption from a text file, and decrypt it.
-WAIT WHAT THE HELL. I just asked you for a decrytion loop but i guess you dont need it? You really need to explain to me how the bitwise xor works then.... It just sunk in that i didn't think it would work while i was typing this

Hmm the only thing i need to work on now, is getting it to put the decryption ness in the text file.
Should i also make it so that, one can put what is needed to be encrypted in a text file? I shall try. Later.
#5 · edited 17y ago · 17y ago
dk173
dk173
Quote Originally Posted by zeco View Post
Oh by the way, in your encryption loop. How exactly does the bitwise xor operator work? I know of it. I just don't know exactly about it. But yeah i need you to right a decryption loops i guess?

I think everything pretty much works so far, well i guess i will provide a change log of sorts.

*The program now outputs the encryption to a text file in the same folder as the EXE.
*It also has a extremely basic front menu
*The program can also now read an encryption from a text file, and decrypt it.
-WAIT WHAT THE HELL. I just asked you for a decrytion loop but i guess you dont need it? You really need to explain to me how the bitwise xor works then.... It just sunk in that i didn't think it would work while i was typing this

Hmm the only thing i need to work on now, is getting it to put the decryption ness in the text file.


next time just edit you post no double posting thx

and i dont know a lick of c++ i cant help
#6 · 17y ago
ZE
zeco
Quote Originally Posted by dk173 View Post
next time just edit you post no double posting thx

and i dont know a lick of c++ i cant help
Thanks.

And @why06
Here is the source code. I have to go away for the weekend in the morning >_<.
Sorry i couldn't help more.

[php]#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void encrypt();
void decrypt();
void start();

int main()
{
start();

system("pause");
return 0;
}

void start(){
short choice = 0;
cout << "Would you like to encrypt, or Decrypt a file?\n" << endl;
cout << "0.) Exit\n";
cout << "1.) Encrypt\n";
cout << "2.) Decrypt\n\n";

(cin >> choice).get();


switch(choice){
case 0:
break;

case 1:
system("cls");
encrypt();
system("cls");
start();
break;

case 2:
system("cls");
decrypt();
system("cls");
start();
break;

default:
system("cls");
start();
break;
}
}

void encrypt(){
ofstream ofile;
ofile.open("encrypted.txt");

char key;
string iput;

cout << "Enter the message you want to encrypt: "<<endl;

getline(cin, iput);
cout << "Enter your encryption key(any character): ";
cin >> key;

for(int i = 0;iput[i]; i++)
{
iput[i] = iput[i] ^ key;
}

cout << "Encrypted message should be in encrypted.txt in the same folder as this program\n";
ofile << "\nHere is your encrypted message: \n" << iput << endl << "\n use key of: " << key << " to decode.\n";

ofile.close();
system("pause");
}

void decrypt(){
ifstream ifile ("decrypt.txt", ios::app);
char key;
string iput;


cout << "Place the text you want to decrypt in the file 'decrypt.txt'"<<endl;

if (ifile.is_open())
{
while (!ifile.eof())
{
getline(ifile, iput);
}
ifile.close();
}

cout << "What key is the input encrypted in?" << endl;

cin >> key;

for(int i = 0;iput[i]; i++)
{
iput[i] = iput[i] ^ key;
}

cout << iput << endl;

//ifile << "\nHere is your encrypted message: \n" << iput << endl << "\n use key of: " << key << " to decode.\n";
//for above to work, class needs to be ofstream, or f stream


system("pause");
}
[/php]
I had gotten further... But then i started to break things in my hyperness... Then i decided it was time to stop, and reverted back to this checkpoint. Good luck =D
#7 · edited 17y ago · 17y ago
LA
lalakijilp
i don't know what all the codes mean yet but maybe is it an idea to make it possible to load text files and then the program makes another text file with the encrypted code in it.

for such a program you need to use somethin other as prompt i think
#8 · 17y ago
why06
why06
Thanks so much zeco xD! Your freakin awesome.

Quote Originally Posted by zeco View Post
Oh by the way, in your encryption loop. How exactly does the bitwise xor operator work? I know of it. I just don't know exactly about it. But yeah i need you to right a decryption loops i guess?

I think everything pretty much works so far, well i guess i will provide a change log of sorts.

*The program now outputs the encryption to a text file in the same folder as the EXE.
*It also has a extremely basic front menu
*The program can also now read an encryption from a text file, and decrypt it.
-WAIT WHAT THE HELL. I just asked you for a decrytion loop but i guess you dont need it? You really need to explain to me how the bitwise xor works then.... It just sunk in that i didn't think it would work while i was typing this

Hmm the only thing i need to work on now, is getting it to put the decryption ness in the text file.
That's the interesting thing :P a xor bit it encryption will return to it's same configuration if you simply xor the message you encrypted by the same value you used to encrypt it. Check it:

1001 1010
^0101 1101
1100 0111

Now All you would do is XOR (that's the exclusive or "^" this symbol) the values again.

1100 0111
^0101 1101
1001 1010

Tada! equals the same bit value we started with. ;P

BTW: thanks a lot. I should be able to figure out the rest now I think.
#9 · 17y ago
ZE
zeco
Quote Originally Posted by why06 View Post
Thanks so much zeco xD! Your freakin awesome.



That's the interesting thing :P a xor bit it encryption will return to it's same configuration if you simply xor the message you encrypted by the same value you used to encrypt it. Check it:

1001 1010
^0101 1101
1100 0111

Now All you would do is XOR (that's the exclusive or "^" this symbol) the values again.

1100 0111
^0101 1101
1001 1010

Tada! equals the same bit value we started with. ;P

BTW: thanks a lot. I should be able to figure out the rest now I think.
No problem, I was really happy to help. TBH i've done like no small programming projects like this. Really to become proficient at a language you need tons of practice. It's a good thing i can retain as much theory as i did though >_<. I seem to remember random places or classes that i just glanced upon previously. Eitherway, good luck, and have fun.

And thanks for the tip on XOR, really i read up on it quite a while ago but i didn't get it. But now it makes perfect sense. Good luck on making it read a text file for encryption. That would probably be easier for larger messages.

Oh another idea, is letting the user specify the name of the file. That would be interesting cause i have a feeling that fstream works for anything that is formatted like a text file, even if the file extension is different, So let's say a C++ source file =D. It would be pretty cool to be able to encrypt and decrypt things like that.
#10 · edited 17y ago · 17y ago
why06
why06
Well here I edited your source code. I combined your Encrypt and Decrypt function into one function. The problem now is it won't print the encrypted/decrypted .txt file in the command window. I'm not sure if it's not reading it or if it's simply not adding it to the string iput :L

Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void encrypt();
void decrypt();
void start();

int main()
{
    start();
    
    system("pause");
    return 0;
}

void start(){
    char choice;
    cout << "Would you like to encrypt, or Decrypt a file?\n" << endl;
    cout << "q.) Quit\n";
    cout << "e.) Encrypt/Decrypt\n";
    
    cin >> choice;


    switch(choice){
    case 'q':
        break;

    case 'e':
        system("cls");
        decrypt();
        system("cls");
        start();
        break;

    default:
        system("cls");
        start();
        break;
    }
}



void decrypt(){
    ifstream ifile ("encrypt.txt", ios::app);
    char key;
    string iput;


    cout << "Place the text you want to decrypt or encrypt in the file 'encrypt.txt'"<<endl;

    if (ifile.is_open())             // I tested this part and nothing executes within this if statement. idk why?
    {                                // Is it that encrypt.txt isn't open? Why not jst read the file without checking if its open or not?
        while (!ifile.eof())
        {
            getline(ifile, iput);
        }
        ifile.close();
    }

            cout << "What key is the input encrypted in?" << endl;

            cin >> key;    

            for(int i = 0;iput[i]; i++)
            {
             iput[i] = iput[i] ^ key;
            }

            cout << iput << endl;
        
    //ifile << "\nHere is your encrypted message: \n" << iput << endl << "\n use key of: " << key << " to decode.\n";
    //for above to work, class needs to be ofstream, or f stream


    system("pause");
}
Lol. ur code is prettier then mine xD
BA probably knows how to make this work out. Hopefully he gets on soon.
#11 · edited 17y ago · 17y ago
Zhhot
Zhhot
Quote Originally Posted by why06 View Post
Lol. ur code is prettier then mine xD
BA probably knows how to make this work out. Hopefully he gets on soon.
who is BA?
#12 · edited 17y ago · 17y ago
B1ackAnge1
B1ackAnge1
Hope you realize that when you XOR a readable ASCII character you will very likely end up with a non-printable character so when you paste it in notepad or any other window it'll not show or look like a weird character. Also using ios:app is for appending which doesn't seem like what you'd want since it seeks to the end of the stream.

Anyway, if you want to put text in the clipboard include windows.h and do something like this:

Code:
void CopyToClipboard(char* text)
{
	HGLOBAL      clipbuffer;    
	char*         temp_ptr ;

	clipbuffer = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, (strlen(text)+1) * sizeof(char));
	temp_ptr = (char*)GlobalLock(clipbuffer);
	strcpy(temp_ptr, text);
	GlobalUnlock(clipbuffer);

	OpenClipboard(0);         // 0 means no window
	EmptyClipboard();
    Se***ipboardData(CF_TEXT, clipbuffer);
	CloseClipboard();
}
Edit: Not sure why it put asterisks in there. it's S e t C l ipboard
Also right now you're X-Oring with a 1-Byte Key.

I'll write up something that'll take a whole string

Edit: Here's a rough draft that'll take an input& output file with a key
or a string with a key (and copies it to the clipboard)
Code:
// Encrypt.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <windows.h>
using namespace std;

void XOR(BYTE* buffer,long length, char* key)
{
	int keyLength = strlen(key);
	int keyIndex = 0;
	for(int i = 0 ; i< length; i++)
	{
		buffer[i] ^= (BYTE)key[keyIndex++];
		if(keyIndex >= keyLength)
			keyIndex = 0;
	}
}

void CopyToClipboard(char* text)
{
	HGLOBAL      clipbuffer;    
	char*         temp_ptr ;

	clipbuffer = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, (strlen(text)+1) * sizeof(char));
	temp_ptr = (char*)GlobalLock(clipbuffer);
	strcpy(temp_ptr, text);
	GlobalUnlock(clipbuffer);

	OpenClipboard(0);         // 0 means no window
	EmptyClipboard();
    Se***ipboardData(CF_TEXT, clipbuffer);
	CloseClipboard();
}

/// Making the main a void since we don't care about what it returns
void main(int argc, char* argv[])
{
	int bufferSize = 0;
	////define some variables we'll be using
	char* filename = NULL;
	char* outputFile = NULL;
	char* text = NULL;
	char* key = NULL;

	//Parse arguments - could be done better
	for(int i = 0; i < argc; i++)
	{
	 if(_stricmp(argv[i],"/fin")==0 || _stricmp(argv[i],"-fin") == 0)
		 filename = argv[++i];
	 else if(_stricmp(argv[i],"/fout")==0 || _stricmp(argv[i],"-fout") == 0)
		 outputFile = argv[++i];
	 else if(_stricmp(argv[i],"/t")==0 || _stricmp(argv[i],"-t") == 0)
		 text= argv[++i];
	 else if(_stricmp(argv[i],"/k")==0 || _stricmp(argv[i],"-k")==0)
		 key = argv[++i];
	}

	//If we're not being called correctly, print out what we expect
	if((argc != 5 && argc != 7) ||  !key || (!filename && !key) || (filename && !outputFile) || (outputFile && !filename))
	{
		cout << "Encrypt Sample for Why06 by B1ackAnge1" << endl;
		cout << "--------------------------------------" << endl;
		cout << "Usage:" << endl;
		cout << "Encrypt a file using a given key:" << endl;
		cout << "Encrypt.exe /fin file.txt /fout file.out /k key" << endl << endl;
		cout << "Encrypt a string using a given key and place on clipboard" << endl;
		cout << "Encrypt.exe /t sometext /k key" << endl;
		cin.get();
		return;
	}

	if(filename) // same as: if(filename != null)
	{
		bufferSize = strlen(key) * 8192; //Don't ask ;)
		BYTE* buffer = new BYTE[bufferSize];
		FILE *fp = fopen(filename,"r+b");
		FILE *fpout = fopen(outputFile,"w+b");

		while(fp && feof(fp) == 0)
		{
			BYTE* buffer = new BYTE[bufferSize];
			int numBytes = fread(buffer,sizeof(byte),bufferSize,fp);
			XOR(buffer,numBytes,key);
			//long curPos = ftell(fp);
			fwrite(buffer,sizeof(byte),numBytes,fpout);
			fflush(fpout);

			delete[] buffer;
		}
		if(fp) 
			fclose(fp);
		if(fpout)
			fclose(fpout);
	}
	else if(text)
	{
		XOR((byte*)text,strlen(text),key);
		CopyToClipboard(text);
	}
}
No guarantees whether or not the above works 100% in all scenarios.. only rudimentary error checking implemented. If you want to make it check if the filekey is correct you could save out a header that needs to always be 'x' after decrypting and give it a custom file extension etc etc
#13 · edited 17y ago · 17y ago
why06
why06
Wow. lol! I just finished geting my rudimentary Encrypter to work after about 4 hours of work xD. And then you come along a type up a source that blows it out of the water. Thanks BA... (guess you know who I'm talking about now Zhhot :P)

I didn't see your post until after I uploaded the whole finished thing and its still really buggy. I need to make it account for the end of the line and write it on a new line. Hopefully I can learn a lot from your code and come up with a second Encrypter that is more robust. right now though I'm gonna take a break from coding... whew!
#14 · 17y ago
B1ackAnge1
B1ackAnge1
Lol, my code is 'blah' at best.. been ages since i've used filestream or File IO.. Sure makes the basic .NET operations seem much more user friendly (which is what I use daily). Sure is fun to screw around with it again though!
#15 · 17y ago
Posts 1–15 of 19 · Page 1 of 2

Post a Reply

Similar Threads

  • need help with moddingBy BayBee Alyn in Combat Arms Help
    0Last post 15y ago
  • Need help finding a Vindictus injectorBy VpChris in Vindictus Help
    2Last post 15y ago
  • I need help~~!!!!By c834606877 in Alliance of Valiant Arms (AVA) Help
    1Last post 15y ago
  • Need HelpBy shane11 in CrossFire Help
    49Last post 15y ago
  • need help with modBy .:MUS1CFR34K:. in Call of Duty Modern Warfare 2 GSC Modding Help/Discussion
    4Last post 15y ago

Tags for this Thread

#encrypter