XOR Encryption Class

Posts 115 of 20 · Page 1 of 2
XOR Encryption Class
Here is a simple XOR encryption class:
Code:
class XOR{
protected:
		char key[256];
public:
	
	XOR(){
		key="fjsldjf84937fd7f6s876df52396tegulhghs87f53f8w987r8970w987erSDFJDFLJSGHHEIHWOHGKDFGSLGDKHSLKDGH";
	}

	char* xorStr(char *string){
		const static int len = strlen(string);
		char* temp = new char(len);
		for(int i = 0; i < len+1;i++)
			temp[i] = string[i]^key[i];
		return temp;
	}
};
Now an example of how to use.
First you create an object of the XOR class:
Code:
XOR* xor = new XOR();
Then to encrypt a string and save it to a variable, you would do:
Code:
char* x=xor->xorStr("lol");
The same function would decrypt the encrypted string, so to get it back, you would do:
Code:
char* orig=xor->xorStr(x);
You can use this to encrypt strings in a hack, or anywhere else
You realize people can view the "lol" string when you call xorStr
Create a separate app to generate encrypted strings, and decrypt them in your actual program...?
Quote Originally Posted by Saltine View Post
Create a separate app to generate encrypted strings, and decrypt them in your actual program...?
There lies the problem, you can't do that with the class you posted
Quote Originally Posted by Refrain View Post
There lies the problem, you can't do that with the class you posted
I realize that now, with my random key generation, I shall fix it, now.
Edit: fixed
Quote Originally Posted by Saltine View Post

I realize that now, with my random key generation, I shall fix it, now.
Edit: fixed
You can still find the key that you're using to encrypt the strings
its not really encrypting if we can still see the string...
Quote Originally Posted by supercarz1991 View Post
its not really encrypting if we can still see the string...
Read the post directly above yours...
Code:
#ifndef _XOR_H
#define _XOR_H
template <int XORSTART, int BUFLEN, int XREFKILLER>

class XorStr
{
private: 
	XorStr();
public: 
	char s[ BUFLEN ];

	XorStr( const char * xs );

	~XorStr()
	{
		for ( int i = 0; i < BUFLEN; i++ ) s[ i ]=0; 
	}
};

template <int XORSTART, int BUFLEN, int XREFKILLER>
XorStr<XORSTART,BUFLEN,XREFKILLER>::XorStr( const char * xs )
{
	int xvalue = XORSTART;
	int i = 0;

	for ( ; i < ( BUFLEN - 1 ); i++ ) 
	{
		s[ i ] = xs[ i - XREFKILLER ] ^ xvalue;
		xvalue += 1;
		xvalue %= 256;
	}

	s[ BUFLEN - 1 ] = 0;
}
#endif


its different from the other one i saw
Quote Originally Posted by AVGN View Post
Code:
#ifndef _XOR_H
#define _XOR_H
template <int XORSTART, int BUFLEN, int XREFKILLER>

class XorStr
{
private: 
	XorStr();
public: 
	char s[ BUFLEN ];

	XorStr( const char * xs );

	~XorStr()
	{
		for ( int i = 0; i < BUFLEN; i++ ) s[ i ]=0; 
	}
};

template <int XORSTART, int BUFLEN, int XREFKILLER>
XorStr<XORSTART,BUFLEN,XREFKILLER>::XorStr( const char * xs )
{
	int xvalue = XORSTART;
	int i = 0;

	for ( ; i < ( BUFLEN - 1 ); i++ ) 
	{
		s[ i ] = xs[ i - XREFKILLER ] ^ xvalue;
		xvalue += 1;
		xvalue %= 256;
	}

	s[ BUFLEN - 1 ] = 0;
}
#endif


its different from the other one i saw
What a pointless use of templates lol.

[at]Thread:
I'm not really sure why you need to make this a class; it doesn't contain any instance-specific info. Would make a lot more sense as a single function, with a param to set a dynamic key. Also, as soon as someone tries to encrypt a string with more chars than the "key", it's going to break. Not sure why the length of the string is static either
Quote Originally Posted by Jason View Post


What a pointless use of templates lol.

[at]Thread:
I'm not really sure why you need to make this a class; it doesn't contain any instance-specific info. Would make a lot more sense as a single function, with a param to set a dynamic key. Also, as soon as someone tries to encrypt a string with more chars than the "key", it's going to break. Not sure why the length of the string is static either
it cant be a single function. it has to store the unencrypted string somehow and clean it up later.
Quote Originally Posted by ISmokeWeedAmICoolNow View Post
it cant be a single function. it has to store the unencrypted string somehow and clean it up later.
Of course you're right! Functions can't return data, how stupid of me.
Quote Originally Posted by Jason View Post


Of course you're right! Functions can't return data, how stupid of me.
what are you going to return? maybe a class?
When you encrypt the string "127.0.0.1" you still see the PUSH to the 127.0.0.1.
If you edit it to "127.0.0.2", the program would encrypt 127.0.0.2.
Posts 115 of 20 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?