Sign in to follow this  
peter_b

need some really simple text encryption method.

Recommended Posts

Hello. I need a really simple text encryption method. I know nothing of encryption, and all i need it for is to make it humanly unreadable. It doesn't have to be secure at all, ease of implementation is most important. It also need to be possible to decrypt just a piece of the entire "file". For instance, sometime i may not read the entire encrypted content of the file, just a small part. So the "key" or whatever you use can't be based on having the entire file. For instance, if i fread() just 20 bytes of encrypted text. I need to be able to decode that without reading anything more. So if someone has a really simple implementation of this to offer me. It would be greatly appreciated++. :-) Thanks in advance.

Share this post


Link to post
Share on other sites
Depend. If you really only want to decrpyt/encrypt text I'd suggest using one of the more simple methods like Caesars Cypher. (This and other very simple methods are explained here: http://www.cs.usask.ca/resources/tutorials/csconcepts/1999_3/lessons/L3/SimpleEncryption.html).

If you are trying to use a (very) simple binary encryption method just xor your Data with a aribtrary key.

Hope that helps. Greetings, Roga

Share this post


Link to post
Share on other sites
XOR encryption will do the job. Something like this:

void XorEncrypt(void* pBuffer, size_t nLen, unsigned char byKey)
{
unsigned char* pBuff = (unsigned char*)pBuffer;
for(size_t i=0; i<nLen; ++i)
*pBuff++ ^= byKey;
}

// Use like so:
char buffer[20];
fread(buffer,1,20,pFile);
XorEncrypt(buffer,20,255);


You decrypt and encrypt using the same function (I.e. you XOR twice). My function will only let you use a key of 0..255, if you want something else, or a password, you'd have to xor with each character of the password. So you'd do "Hidden Data" (xor'd with) "PasswordPas"; I.e. repeat the password to make it the length of the data.

Share this post


Link to post
Share on other sites
If I'm right he wanted text encyption. The suggeste XOR encryotion is a binary method. So if he want's to keep it simple and human readable Caesar seems pretty fine to me.

Share this post


Link to post
Share on other sites
Quote:
Original post by Rogalon
If I'm right he wanted text encyption. The suggeste XOR encryotion is a binary method. So if he want's to keep it simple and human readable Caesar seems pretty fine to me.

Quote:
I know nothing of encryption, and all i need it for is to make it humanly unreadable.
I took that to mean that he doesn't want it to be text at all. I suppose it can be taken both ways though. But yes, a Caesar cyper would certainly be fine if he wants the output to be human readable, or at least ASCII.

Share this post


Link to post
Share on other sites
thank you all for your replies! The xor method looks exactly like what i was looking for, nice and simple.


Again, thanks!

Share this post


Link to post
Share on other sites
I've seen base64 used as a simple "encryption method" that keeps the output in ASCII.

There is also always the classic rot13.

Both have the advantage (or disadvantage...) of having plenty of sample implementations floating around to reuse.

Share this post


Link to post
Share on other sites
Quote:
Original post by NotAYakk
Rot thirteen is the best cypher.
Nobody can defeat rot thirteen.
The main problem with rot13 is that it looks like it's rot13. I just looked at your post and knew it was rot13. At least a Caeser cyper has 25 possabilities I could have tried before discovering the real message.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this