Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello there! i will be as short as i can, i understant xor encryption, and i want to encrypt then decrypt some text in a specific file.

example file.dat:
text1
text2
text3
text4
text5


I am able to make XOR encryption, but i just can`t do it line by line, especially decrypting it while reading...
Can someone give me an example please?
Thank you very much!
Posted

1 solution

"Line by line" doesn't make much sense when you talk about encryption - even a system as simple as XOR - simply because the results of the encryption process can be any value including the end of line code.

So if you encrypt it by line, then presumably you want the output to also be line oriented: which means you need to skip the "line end characters" in the original data and transfer them "as is" to the output file. But...what if your encrypted data generates line end characters (as it can, very easily)? When you come to decrypt it, you don't regenerate the original file because you can't tell which lines in your encrypted input are "real" and which aren't.

Always treat encrypted data as binary - reading to encrypt and reading to decrypt - never as text, or you will find times when your encrypted data cannot be recovered!
 
Share this answer
 
Comments
[no name] 26-Mar-15 3:27am    
Thanks for answering sir, is there any other method i can use for encrypting my data? i really need it line by line, because my function needs to read line by line...
OriginalGriff 26-Mar-15 3:36am    
You could - but it would be a lot more complex.
Because the "real" data you encrypt could be anything, including text based line end characters, you would have to keep an index at the top of the file which indicated where lines start and stop (either in terms of "this byte number is the start of the line" or "this line is nnn bytes long" for each line) and then read that first when you try to decrypt it. Messy.

And there is another problem: most encryption is not XOR (that's very, very poor in encryption terms and spectacularly simple to break) and "proper" encryption doesn't lend itself to line based work in any way, shape or form - in fact trying to use it in a line based way would make the whole file much, much more vulnerable to attack!

What are you trying to do that you need this? There may be a better way.
[no name] 26-Mar-15 3:42am    
I have a protection against cheats, and for example i scan opened windows, so if i have a window named Cheat v.1 or Cheat v.2 bam, the process exits, also i have memory dumps, in this format: {0x405AF8, {0xe8, 0x03, 0x3d, 0x00, 0x00, 0xe9, 0x79, 0xfe, 0xff, 0xff, 0x8b, 0xff, 0x55, 0x8b, 0xec, 0x8b, 0x45, 0x08, 0xa3, 0x9c, 0xc0, 0x41, 0x00, 0x5d, 0xc3, 0x8b, 0xff, 0x55, 0x8b, 0xec, 0x81, 0xec}}, // elite 3.4
same thing here also, i can be much more easier for me to add cheats in a so called "database" rather then recompiling again and again everytime a new cheat appears.
I saw something in a particular software, but i was line by line, something in this format:

1=adsadadas
2=asdasdsadasdada
3=asdsadasdasdasdasdad

from here i got the idea to somehow make something similar to this... but i am more a php coder, so in c++ beginner i can say...
OriginalGriff 26-Mar-15 4:41am    
Why not use a database?
Or just use "proper" encryption and read the whole file? Memory probably isn't a problem - the size of your file is going to be pretty trivial in modern memory terms - so encrypt the whole file using DES or similar and read the decrypted result into you app as an array of strings. Probably work out quicker as well.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900