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 / Base64 encryption help...

Author
Message
Non Sequitur M
17
Years of Service
User Offline
Joined: 28th Oct 2008
Location: Where am I!? Where are YOU?
Posted: 17th Jun 2011 08:04
Okay. I'm looking at using a Base64 encryption password to save player data for a game. Yes, I know there are better ways of doing this(Like an actual save file), but it's for authenticity of a remake.

I'm using this char set:


Currently, I plan to convert each number of the game info to be saved into it's binary string equivalent, perform all of the checksums on the data(To make sure there can't be a bum password entered), and then, using the text commands to comb through the data, I chop it up into 6 bit sections, which are then converted into a letter from the above list.

My question is, is there a really efficient way to create the 6 bit characters? Because, my way is the best I can come up with. But, I know there has to be a better way.

Thanks,
-Amo.

If the universe isn't a program, then why do planets orbit in loops, death sparks life, and human interaction is buggy and glitched?
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 17th Jun 2011 11:41 Edited at: 17th Jun 2011 11:52
I've never done Base64 encryption so I had to look it up in Wikipedia. I recently posted an encryption routine that used a random seed so the computer can pick it's own encryption key. I used the same method in the following code snip (without the randomness) using a string with Base64 as the key. It uses IanMs Matrix 1 Utilities Plugin so get it now if you don't have it.

https://forumfiles.thegamecreators.com/download/2192430

I used the same text example as the one on Wikipedia to make sure it worked properly (your key is a bit different than Wiki though).

http://en.wikipedia.org/wiki/Base64



Non Sequitur M
17
Years of Service
User Offline
Joined: 28th Oct 2008
Location: Where am I!? Where are YOU?
Posted: 17th Jun 2011 19:46
That's great! Thanks again, Grog! Yeah, I plan to randomize the seed every time the game starts up. There will also be special checksums like I mentioned that allows only legit passwords. And, I already have Matrix1. Great plug-in. One of the best IMO. I totally forgot to look through his commands. Thanks.

If the universe isn't a program, then why do planets orbit in loops, death sparks life, and human interaction is buggy and glitched?
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 17th Jun 2011 21:39 Edited at: 17th Jun 2011 21:40
Quote: "That's great! Thanks again, Grog! Yeah, I plan to randomize the seed every time the game starts up."


Np. Actually about a couple of months ago IanM informed us that Darkbasic Pro automatically picks a random seed when it starts up so we don't have to do that anymore.

Quote: "And, I already have Matrix1. Great plug-in. One of the best IMO. I totally forgot to look through his commands. Thanks."


Well the only commands used are his version of MID$() (which is the normal Basic/GWBasic version that allows taking more than one character (in this case 6 and 8 characters at a time)) and his BIN TO DECIMAL() command which converts binary to decimal (for decryption). The BIN$() command that changes a decimal to a binary is a native Darkbasic command. It outputs a 32 bit binary string but it's easy to grab the last 8 bits for encryption.

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 18th Jun 2011 00:19 Edited at: 18th Jun 2011 00:19
That's not really the standard Base64 table that people use. Replace your ! and ? with + and /. The equal sign is used for padding.

Take a look at my code, might help you.
http://forum.thegamecreators.com/?m=forum_view&t=75214&b=6

Non Sequitur M
17
Years of Service
User Offline
Joined: 28th Oct 2008
Location: Where am I!? Where are YOU?
Posted: 18th Jun 2011 02:44
@Grog: I still would feel safer using my special reseed function. Just because I don't know exactly how DBP reseeds. Also, if Ian's plug-in has a command that is functionally similar to a native command, because of the track record of both DBP and Matrix1, I usually go with the Matrix1 command! Haha.

@Phaelax: No, it's not the standard table, that's why I put that in there. Also, due to the nature of what this is for, I can't use padding. It would unnecessarily increase the size of the password.

---

Also, I forgot to mention that it has to store quite a few numbers, but Grog's code is a great base to start with. So far, I have it storing a byte for checksums, a few bytes for Boolean data, a player's name, a byte for a player's location, and a few bytes for item data, level data, quest completion, etc. Yours is nice, too, Phaelax. Although, a bit lengthy. But, in the end, I should have it figured out soon.

If the universe isn't a program, then why do planets orbit in loops, death sparks life, and human interaction is buggy and glitched?
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 18th Jun 2011 03:42 Edited at: 18th Jun 2011 05:03
OHHH! i typed a message then it dawned on me what you were saying xD



I'd make something using a bitwise manipulation functions. Basically, put all your data into an array of bytes. Now, a byte is 8 bits long, and the least common multiple of 8 and 6 is 24. (8*3=6*4) So if you have 4 6 bit numbers and 3 8 bit numbers, that looks something like this in binary:

(where A/B/C/D are bits of different numbers)

So, I'd do something like this (DBPro style pseudo-code, I'm using the post-message form as an editor here and not testing it in DBPro, but I'll try to use proper syntax xD)





That should work. Then you could parse the string back into a byte array, then the byte array back into meaningful data structures.

[edit]
Hmm... I think all those | symbols need to be replaced by ||, and & with &&.
[edit2]
alright I got to thinking about how to do this well, and I think I'm going to make a bunch of base64 string/datatype conversion functions. Also, I don't think "encryption" is the right word. It's more just changing format.


Why does blue text appear every time you are near?
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 18th Jun 2011 21:51
Quote: "Also, due to the nature of what this is for, I can't use padding. It would unnecessarily increase the size of the password."

If size is a concern, you probably shouldn't use this type of encoding.

Non Sequitur M
17
Years of Service
User Offline
Joined: 28th Oct 2008
Location: Where am I!? Where are YOU?
Posted: 18th Jun 2011 23:12
It's for a password. The original game I'm making this remake of used a modified Base64 to encrypt the password. The padded characters are the only unnecessary thing. Although, I'm having to slightly modify theirs as well. Although, it's coming along with the help I've received here.

I'm using 4 Base64 bytes to encrypt numbers ranging from 262144-16777215, 3 bytes for 4096-262143, 2 for 64-4095, and 1 for 0-63. It's working beautifully on paper! Ha! XD Let's hope it does the same in program!

If the universe isn't a program, then why do planets orbit in loops, death sparks life, and human interaction is buggy and glitched?

Login to post a reply

Server time is: 2026-07-11 12:15:40
Your offset time is: 2026-07-11 12:15:40