Encryption & Strings?

Neptune

Member
Say I have a string... "93723647FHJDK" or some other fairly lengthy mix of alpha numerics.
Is there a common way to compress / encrypt something like this into a smaller string (or even a different datatype), but still uniquely representing the old string - which can later be reversed?

Any information is appreciated!
 

Neptune

Member
Hmm, I suppose I should have clarified, I'm wondering about a smaller character representation -- I don't necessarily care how many bytes it is.
If there is some kind of conversion that would turn "93723647FHJDK" into, say... "XX$0T10#"
I suppose this may be an unrealistic ask!
 

Gamebot

Member
Without a "hash" algorithm all of your letters, digits and symbols already represent ( from a computer point ) the least amount of characters needed.

While not super secure you could create a struct or other lookup in which each single and/or every two characters always equals one character. However, just using alphanumeric would be close to about 1325 possibilities and about 72 characters to choose from, at least on my keyboard ( unless your going for a useable font with many more symbols too. )
 

peardox

Member
If you're not concerned about security and really wanna obfuscate the data then XOR-ing against some seeded random would work.

To do this kinda thing properly you'd want something like twofish but writing a function to do that in GML would be extremely inefficient, an extension in portable C would be the proper way to do it
 

TsukaYuriko

☄️
Forum Staff
Moderator
Hmm, I suppose I should have clarified, I'm wondering about a smaller character representation -- I don't necessarily care how many bytes it is.
Since you don't seem to be after smaller file size: What's your motivation behind wanting this? Knowing that may make it easier to suggest solutions that work for your usage case.
 

Joe Ellis

Member
I think generally encryption works with a password that's used as the seed for the randomizer that scrambles the data. You can make your own basic scrambler using irandom and make it add n to each byte of data, (also make it wrap around 0-255 if you're doing it per byte)
Then as long as you use the same seed you can reverse it just by subtracting instead of adding
 

peardox

Member
I think generally encryption works with a password that's used as the seed for the randomizer that scrambles the data. You can make your own basic scrambler using irandom and make it add n to each byte of data, (also make it wrap around 0-255 if you're doing it per byte)
Then as long as you use the same seed you can reverse it just by subtracting instead of adding
Which is why I said use XOR

Message XOR RandomizedCrap => garbage
then
garbage XOR RandomizedCrap => Message

You're describing something like ROT13
 
Top