Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] - XXTEA (Tiny Encryption Algorithm) code for DBPro

Author
Message
The Sab
15
Years of Service
User Offline
Joined: 4th Dec 2008
Location:
Posted: 19th Oct 2011 15:03 Edited at: 19th Oct 2011 16:09


This is working code for XXTEA (Tiny Encryption Algorithm) created by Roger Needham and David Wheeler. The implementation I based this version on is a java script by Chris Veness, as he added functionality to encrypt strings instead of just binary data.
It can be seen here:

http://www.movable-type.co.uk/scripts/tea-block.html

To encrypt a string use the function:
'ciphertext$ = encrypt(<plaintext$>, <password$>'

and to decrypt:
'message$ = decrypt(<ciphertext$>, <password$>'

!HOWEVER!
There are a couple of strings that do not encrypt/decrypt correctly, and I am at a complete loss as to why. For example, the string:
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012"
does not make it through the algorithm correctly, but if you add or remove a character to it, it passes through fine. I am not a crypto-analyst and I have gone over the code a few hundred times and still cannot find the problem. If you are interested in this sort of thing, please let me know what you think.
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 20th Oct 2011 07:52
can you make a program to encrypt images or any sort of media in the case someone wants to keep them safe?

t is s gnat re h as ben destro ed by A m d
The Sab
15
Years of Service
User Offline
Joined: 4th Dec 2008
Location:
Posted: 20th Oct 2011 16:10
Heh, keep in mind that I did not actually write the encryption code so much as translate it from another language. Ultimately, the algorithm will work on any piece of data, provided it can be converted to numbers. An image file (that is compatible with DBPro) wouldn't be too hard, as a bitmap is easily converted to bytes. Something like encrypting a video file, or just any arbitrary file might be a little tougher, as DBPro may not grab the data properly from anything not made in DBPro. I will fiddle around with it and get back with you.

Also keep in mind that there is the above mentioned bug that I was talking about, where occasionally there are things that don't seem to work in the algorithm.
The Sab
15
Years of Service
User Offline
Joined: 4th Dec 2008
Location:
Posted: 20th Oct 2011 19:43 Edited at: 21st Oct 2011 01:44
It turned out to be easier than I thought. Here is the code for the two .dba files. The first is just a quick and rough app. The second is the encryption algorithm. Note that I had to make some changes to the algorithm file, so it is different from the previous one I posted earlier.





I threw this together in a couple of hours, so I won't claim to have done exhaustive testing on it. It does not overwrite the original files, but instead creates encrypted/decrypted copies.
It has worked on the few files I tried it on, and seems to be working well. Feel free to modify (as if I could stop you) or rewrite any of the code to suit your needs.

<Edited>
Also keep in mind that this is encryption, not compression. Encrypting something the size of a reasonable size jpeg will only take a few seconds. Something the size of full length song in mp3 format may take several minutes. A full length movie would probably take several hours. This algorithm was originally designed to encrypt internet traffic like emails and instant messages.

Login to post a reply

Server time is: 2024-03-29 14:47:27
Your offset time is: 2024-03-29 14:47:27