#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Source of an encrypting proggy, and a decrypting one

Member Posts: 2
Hey ho everyone.

I wrote these at home, and I want some comments and remarks.

http://server6.uploadit.org/files/sabato-encrypt2.jpg
http://server6.uploadit.org/files/sabato-decrypt2.jpg
Change the file extensions to ".pas". Sorry, but uploadit.org only allows .jpg files.

Please do reply. If you could write on your replies how efficient the encrypting method is in your opinion, I'd be pleased. And oh, feel free to write if there's something you don't understand.

Have fun,
---Sabato

## Comments

• Member Posts: 6,349
: Hey ho everyone.
:
: I wrote these at home, and I want some comments and remarks.
:
: http://server6.uploadit.org/files/sabato-encrypt2.jpg
: http://server6.uploadit.org/files/sabato-decrypt2.jpg
: Change the file extensions to ".pas". Sorry, but uploadit.org only allows .jpg files.
:
: Please do reply. If you could write on your replies how efficient the encrypting method is in your opinion, I'd be pleased. And oh, feel free to write if there's something you don't understand.
:
: Have fun,
: ---Sabato
:
:
:
This looks like a very poor encryption, since you always need to ship the unprotected key with the data. This allows a third party to intercept both and start playing with maths to find the encryption function. As for the function itself: XOR is a very basic functions, which I would check as one of the first (along with addition and subtraction).
You can slightly improve the encryption by making it a stacked encryption method. For example:
[code]
Data^[j] := (Data^[j] + Data^[j-1]) XOR Key^;
[/code]
This way you introduce another variable into the encryption equation.
The code itself would be much cleaner and easier to read if you had used an encryption procedure, which takes two (or three) parameters: source filename and destination filename (and the key filename).
You also open the same three files three times, which is quite a drain on resources, because only so many files may be opened by a program. You can do the better, by using an untyped file, BlockRead(), and BlockWrite() to control how many bytes you want to read/write at a time. This allows you to encrypt in blocks of 64k, and then the last block is as big as it needs to be. The number of blocks is then reduced to (FileSize div 64k)+1.
• Member Posts: 2
[b][red]This message was edited by Sabato at 2004-3-18 23:1:1[/red][/b][hr]
: : Hey ho everyone.
: :
: : I wrote these at home, and I want some comments and remarks.
: :
: : http://server6.uploadit.org/files/sabato-encrypt2.jpg
: : http://server6.uploadit.org/files/sabato-decrypt2.jpg
: : Change the file extensions to ".pas". Sorry, but uploadit.org only allows .jpg files.
: :
: : Please do reply. If you could write on your replies how efficient the encrypting method is in your opinion, I'd be pleased. And oh, feel free to write if there's something you don't understand.
: :
: : Have fun,
: : ---Sabato
: :
: :
: :
: This looks like a very poor encryption, since you always need to ship the unprotected key with the data. This allows a third party to intercept both and start playing with maths to find the encryption function. As for the function itself: XOR is a very basic functions, which I would check as one of the first (along with addition and subtraction).
: You can slightly improve the encryption by making it a stacked encryption method. For example:
: [code]
: Data^[j] := (Data^[j] + Data^[j-1]) XOR Key^;
: [/code]
: This way you introduce another variable into the encryption equation.
: The code itself would be much cleaner and easier to read if you had used an encryption procedure, which takes two (or three) parameters: source filename and destination filename (and the key filename).
: You also open the same three files three times, which is quite a drain on resources, because only so many files may be opened by a program. You can do the better, by using an untyped file, BlockRead(), and BlockWrite() to control how many bytes you want to read/write at a time. This allows you to encrypt in blocks of 64k, and then the last block is as big as it needs to be. The number of blocks is then reduced to (FileSize div 64k)+1.
:

I see your point, but I think that creating an encryption that is safe even if the other side has the key, is quite impossible.
As for my own way of encrypting the file - I did it in order to make the encrypted file seem absolutely random (which it is), so that a cracker wouldn't have a chance to see patterns, for example. He would only know that the original file's size is the same as the encrypted one (and even that's not for sure). Obviously, NO encryption is safe if the other side has the key.
Now, as for BlockRead() and BlockWrite() - I've experimented with these. I once tried to create a copy program that would be faster than the Windows and DOS copy (I eventually succeded - with files of ~600MB, my copy routine was about 10 seconds faster). While I was doing this, I explored all the ways possible to read from and write to files, and for some obscure reason - BlockRead() and BlockWrite() were [i]slower[/i] than read() and write() (when reading in chunks of 64K).
About putting the encryption itself in a proc or func - I don't belive it would help much, since the core itself is 40 lines long (yes, I know i could make it 1/3 if I'd use BlockRead() and BlockWrite(), but I prefer not to, for the reasons stated above).

• Member Posts: 757
It does what you set out to do, A few suggestions though:

* The key gets repetitive. Why use double the original file space when you could save just the 262 bytes (or whatever size) into a key file.

* Allow parameter passing for the file to encode/decode or a basic GUI

* XOR is a weak encryption. Instead, why not generate a random seed and save the seed number to the first couple of bytes of the file (or for extra safety measure, some other point in the file such as the middle or end)

* Add on a password feature so that the key and a password is needed

* Only allow decrypting of the file if the proper key is given

Looks like a good start. Hope to see some updates.

Phat Nat

: Hey ho everyone.
:
: I wrote these at home, and I want some comments and remarks.
:
: http://server6.uploadit.org/files/sabato-encrypt2.jpg
: http://server6.uploadit.org/files/sabato-decrypt2.jpg
: Change the file extensions to ".pas". Sorry, but uploadit.org only allows .jpg files.
:
: Please do reply. If you could write on your replies how efficient the encrypting method is in your opinion, I'd be pleased. And oh, feel free to write if there's something you don't understand.
:
: Have fun,
: ---Sabato
:
:
:

Sign In or Register to comment.