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.

Newcomers DBPro Corner / How does string encryption work?

Author
Message
Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 24th Jun 2011 19:43
Hey everybody. I'm looking for a way to encode and decode a string, for savegames and such.

Been at this for quite some while, but the two relative simple sollutions are code words and fake data and such. Simple yes, but a lot of work and not flexible. The other one is to tie each character to a number and go from there, but I can't seem to pull that one off.

So I need a little help...

Lets say I have a string$ = "John was here!"

and I would want to encode it into a string made of numbers through a function and then reverse the process as well.

Can anyone help me with this? Thanks a lot!!

Regards Sph!nx
http://www.mental-image.net
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 25th Jun 2011 00:32
You can make it more or less complicated.
The easiest (but pretty worthless safety-wise) approach is, as you suggested, to have each character correspond to a different character / value and the just replace all characters in the source string to conform to that. Of course every one character should be represented by one unique number so that it cannot get mixed up.
The easiest way to carry out this in DBPro would be to have a constant array set up that maps the characters to other values based on their ASCII codes (the asc() function will come in handy to get the ascii value from a single character, that can be retrieved from a string using the mid$() function). The mapping must be consistent so that if, say the letter "K" previously corresponded to the value '99', it must do so in all future (as well as previous) runs, or you'll get into trouble when you want to decrypt the string. Which in this case is obviously done by carrying out the reverse operation of replacing the numbers with their corresponding characters again.

To achieve more complicated encryption, you could do a number of things, such as having a key (like a password) that is in one way or another combined with the source string to produce the encrypted string and therefore is also required to decrypt it again. You can also borrow elements from compression, such as variable-bit mappings of the characters, etc.


"Why do programmers get Halloween and Christmas mixed up?"
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 25th Jun 2011 07:45
Have a look at this thread. I think this is very useful.

A clever person solves a problem, a wise person avoids it - Albert Einstein
Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 25th Jun 2011 14:38 Edited at: 25th Jun 2011 17:05
Thanks a lot guys!

@ Rudolpho: So, it I'm on the right track and it is as hard as I thought! :-P

@ Hodgey: Yup, saw that thread before (replied in it as well). I'm doing my research!

Well, I'll be trying to set this up and post any findings and solutions I might find in this thread for others as well. Thanks again guys!

Edit:
Found another solution! What if I pack the data file into a 'fileblock' (DB Enhancements Library) and only have the data file extracted during a load and save process and keep it packed otherwise!

Pro: I can pack more than just a data file if I need to!
Con: There is still window of a few seconds to view the data file outside the main pack (actual save file). (But hey, if people would actually notice and are that eager to cheat, be my guest!)

This is still just an idea... Please reply if you got an opinion or suggestion!

Regards Sph!nx
http://www.mental-image.net
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 26th Jun 2011 04:52
Quote: "@ Hodgey: Yup, saw that thread before (replied in it as well)."

How did I miss that? Well the memblock method is probably what I would use.

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 26th Jun 2011 04:52
I do encryption routines all the time for fun. Here's some of the recent ones:

Close to the bottom is my encryption routine that uses a random seed:
http://forum.thegamecreators.com/?m=forum_view&b=7&t=185300&p=0

This one is using Base64 encryption:
http://forum.thegamecreators.com/?m=forum_view&t=186051&b=1

Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 26th Jun 2011 09:12 Edited at: 26th Jun 2011 09:35
@ Hodgey: You can't see everything all the time. The help is appreciated!

@ Grog Grueslayer: Looked at the threads and I believe the first link you posted might contain the thing that I need. Thanks!

Edit:
@ Grog Grueslayer: Haven't implemented it in my code yet but I've tested in a separate exe. It works like a charm and it's just what I need! Thanks again!

Your name, as well as anyone who helped (or attempted) will be listed in the credits of my project. You can take a look here, but know, the page and what you see on it is very outdated by now...

Edit2:
Isn't there a way to edit the thread title or tag the thread as solved? (For others in the future who search to board...)

Regards Sph!nx
http://www.mental-image.net
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 26th Jun 2011 17:57 Edited at: 26th Jun 2011 17:57
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 26th Jun 2011 18:52 Edited at: 26th Jun 2011 18:58
@ Kevin Picone:

That's a pretty cool way to do quick encryption/decryption.


@ Sph!nx:

Go to that link and read the message but run the following.

This is Kevins encryption code converted to Darkbasic:


Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 26th Jun 2011 23:52
GG,

It's as old as the hills, then again.. so am I

Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 8th Jul 2011 17:40
Awesome! Thanks guys! Previous code works like a charm but this looks even better for my purpose.

Much appreciated guys!

Regards Sph!nx
http://www.mental-image.net

Login to post a reply

Server time is: 2024-11-22 19:07:06
Your offset time is: 2024-11-22 19:07:06