ROT Encryption

If you have a cool piece of software to share, but you are not hosting it officially yet, please dump it in here. If you have code snippets that are useful, please donate!
Post Reply
CrashX
In need of some credit
In need of some credit
Posts: 5
Joined: Sun Jan 27, 2008 8:52 pm

ROT Encryption

Post by CrashX » Sun Jan 27, 2008 9:12 pm

ROT Encryption( http://en.wikipedia.org/wiki/ROT13 ) done using wxWidgets.

Code:

Code: Select all

wxString RotEncryption( const wxString & pStr, int pLowerLimit, int pUpperLimit )
{
	int offset = (pUpperLimit-pLowerLimit)/2+((pUpperLimit-pLowerLimit)%2);
	wxString encrypted = pStr;
	wxChar data;
	for(unsigned int i=0; i < pStr.length(); i++)
	{
		data = pStr.GetChar(i);
		if((data >= pLowerLimit) && (data <= pUpperLimit ))
		{
			if( ( data > ( pUpperLimit - offset ))
			 || ( data < ( pLowerLimit - offset )) )
			{
				data = data - offset;
			} else
			{
				data = data + offset;
			}
		} 
		encrypted.SetChar(i,data);
	}
	return encrypted;
}
Usage:

Code: Select all

wxString encrypted = RotEncryption(RotEncryption(_T("Welcome to wxWidgets!"),32,(1<<(8*sizeof(wxChar)-1))-1),-1<<((8*sizeof(wxChar))-1),-1);
	wxString decrypted = RotEncryption(RotEncryption(encrypted,-1<<((8*sizeof(wxChar))-1),-1),32,(1<<(8*sizeof(wxChar)-1))-1);

Notes:
- Lower and Upper value can't be both odd or even.
- The above example uses range NEGETIVE_MAX_CHAR to -1 and 32 to POSITIVE_MAX_CHAR to do encryption.

priyank_bolia
wxWorld Domination!
wxWorld Domination!
Posts: 1339
Joined: Wed Aug 03, 2005 8:10 am
Location: BANGALORE, INDIA
Contact:

Post by priyank_bolia » Mon Jan 28, 2008 2:58 am

But why you want to use such easy to break encryption, why not wx3DES, etc.

CrashX
In need of some credit
In need of some credit
Posts: 5
Joined: Sun Jan 27, 2008 8:52 pm

Post by CrashX » Mon Jan 28, 2008 3:56 pm

Well if you keep running this function with different ranges then it becomes a bit more difficult to break. :?

Where can I download wx3DES ? Source Code ?

priyank_bolia
wxWorld Domination!
wxWorld Domination!
Posts: 1339
Joined: Wed Aug 03, 2005 8:10 am
Location: BANGALORE, INDIA
Contact:

Post by priyank_bolia » Mon Jan 28, 2008 4:21 pm

wxTripleDES from http://priyank.co.in
You need to register first before downloading.

and wxDES is available directly also from Carlos Dominguez. I don't have the link now.

phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Post by phlox81 » Mon Jan 28, 2008 7:05 pm

Take a look at Crypto++, its one of the best encryption libraries for c++.
http://www.cryptopp.com/

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Tue Jan 29, 2008 8:08 am

CrashX wrote:Well if you keep running this function with different ranges then it becomes a bit more difficult to break. :?
Sorry, but this is not quite correct. using different ranges won't make it harder to break or more secure. In fact it won't change a thing if I already guessed that it might be a kind of ROT algorithm.
CrashX wrote:Where can I download wx3DES ? Source Code?
Most algorithm that are considered to be "secure" have free implementations flying around. Crypto++ is quite good, openssl has many encryption modules available as well.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

Post Reply