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.

DarkBASIC Professional Discussion / XOR HEX Encryption-Decryption

Author
Message
Flatlander
FPSC Tool Maker
19
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 28th Mar 2011 08:44 Edited at: 28th Mar 2011 21:24
Edited:

There are dozens of algorithms regarding encryption and decryption. I wanted to take a simple algorithm to turn the algorithm into DBPro code.

The code is fixed now and everyone has my permission to use it if they like.



I use IaM's matrix util #7 that has a hex to decimal routine. So you will have to have that available. If you happen to have FPSC source code that you would want to put this in then you will need to rename Lee's variable "pi" to something else.


Terry
Flatlander
FPSC Tool Maker
19
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 28th Mar 2011 17:35 Edited at: 28th Mar 2011 21:26
IanM reminded me to be patient. So, I decided to delete my impatient comments.


Terry
=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 28th Mar 2011 18:05
I have had a quick look, but its a bit more than a 5 minute tea break job. I'll have a proper look tonight or tomorrow.

If you solve it in the mean time, plz post the solution here

Flatlander
FPSC Tool Maker
19
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 28th Mar 2011 19:49 Edited at: 28th Mar 2011 19:51
It definitely is more than a 5 minute tea break. Better to spend time having a biscuit with your tea than this. :LOL:

I probably will not have time yet today. Lots of errands for the wife to run . Thanks for taking the time to respond and for taking a look.


Terry
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Mar 2011 19:58
Quote: "I figured nobody would take the challenge. Even with the code pretty much given."

Patience!

The problem is with the following line:


I have no idea why you are trying to read a decimal number from a hex value, then converting that to hex.

What you should have used:


Flatlander
FPSC Tool Maker
19
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 28th Mar 2011 20:59 Edited at: 28th Mar 2011 21:26
Thanks IanM. I figured the genius of the board would get it right away. :LOL:


Quote: "I have no idea why you are trying to read a decimal number from a hex value, then converting that to hex.
"


I just don't know why I did that either. But it sure did elude me.

As far as being impatient. That seems to be what is happening to me now that I'm 70. Part of it is the dementia and problems with brain chemicals. I have always been more patient than I am now. And another thing, I seem to express that impatience when I shouldn't.

So, anybody who wants to use this can. You have my permission. It is not a Government approved encryption but it works for minor stuff you may want encrypted. If you want to give credit fine. But, by the time someone may use this publicly, I'll probably be babbling and drooling out of my mouth and won't even care. :BIG LAUGH:

Thanks again, IanM.

Oh, to make it easier, I changed the code in the original post to be correct. So the original post is good to go.

BTW, is this worth posting up on the TGC source code area or whatever you call it?


Terry
=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 28th Mar 2011 23:22
I came back, but IanM had fixed it while I was at work...

Yay for IanM.

I am tempted to look into this as it's similar, but much more advanced than the encryption method I'm using for one of my on again off again projects.

BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Mar 2011 23:55
Flatlander, as a minor you shouldn't tell people your...oh hang on, there's a zero on the end

I think that must make you the official veteran of the boards. Green Gandalf will be feeling like a spring chicken.

OK, I've insulted 2 respected members of the board, time to leave quietly...

Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 29th Mar 2011 00:53 Edited at: 29th Mar 2011 00:59
F l a t l a n d e r,

Just a bit of a tip really, rather than compute the length of the strings inside the encode or decode loops, pre-compute them a temp variables, then use those.

This sort of thing,



Note: code is untested!

So we've just removed a few function calls per character. So the longer the fragment being encoded the more potential gain. The same of the decoder though.

If you get a pointer to the string character data, that'd be a more optimal solution (32 or 64 bits groupings) , but anyway.

Flatlander
FPSC Tool Maker
19
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 29th Mar 2011 05:34 Edited at: 29th Mar 2011 08:28
@=PRoF=

I sure you would have fixed it quickly once you felt you had the time.

@BatVink

OMGossh, I've been modded. :LOL:

@Kevin Picone

Now as far as a veteran -- meaning a veteran of the boards -- you're definitely one of the earliest members I've seen. You've got 5 years on me.

Thanks for the optimization tips. They do work.

@Everyone who is interested

Here is the code that includes the optimization suggested by Kevin.




Terry
Flatlander
FPSC Tool Maker
19
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 29th Mar 2011 08:27 Edited at: 29th Mar 2011 08:29
There is a possible drawback to this algorithm. I had forgotten all about it until I started testing this in an app.

The length of the data string in the decryption function is the same length as the non-encrypted data string. This makes it somewhat problematic as how will one obtain that value. It is easy if it were the length of the encrypted data string; but, it is not. Somehow we have to provide that value when we want to decrypt a string. It needs to be available somewhere and somehow.

Every developer will have a different use and therefore will need to come up with there own method. I have come up with my own plan but I'm not happy with it right now. However, like a lot of code, it may grow on me.


Terry

Login to post a reply

Server time is: 2026-06-06 02:56:01
Your offset time is: 2026-06-06 02:56:01