• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Thoughts on this Encoding/Decoding Algorithm

cdgamedev

Member
Hi all!

I just created a encryption/decryption algorithm using base64_encode and base64_decode.

Code:
/// String encode algorithm
var String = argument0;
var Output = "";
for(var i = 1; i <= string_length(String); i++) {
    Output = base64_encode(Output + string_copy(String, i, 1));
}

return Output;

Code:
/// String decode algorithm
var String = "";
var Output = argument0;

do {
    Output = base64_decode(Output);
    String = String + string_copy(Output, string_length(Output), 1);
} until(string_length(Output) = 1);

Output = "";

for(var i = string_length(String); i >= 1; i--) {
    Output = Output + string_copy(String, i, 1);
}

return Output;

What are your thoughts? Is it a good idea to do something like this as it makes it more difficult to decode?

Only issue comes down to longer strings... as I just found out
 
Last edited:
S

Shawn Shipton

Guest
Hi all!

I just created a encryption/decryption algorithm using base64_encode and base64_decode.

Code:
/// String encode algorithm
var String = argument0;
var Output = "";
for(var i = 1; i <= string_length(String); i++) {
    Output = base64_encode(Output + string_copy(String, i, 1));
}

return Output;

Code:
/// String decode algorithm
var String = "";
var Output = argument0;

do {
    Output = base64_decode(Output);
    String = String + string_copy(Output, string_length(Output), 1);
} until(string_length(Output) = 1);

Output = "";

for(var i = string_length(String); i >= 1; i--) {
    Output = Output + string_copy(String, i, 1);
}

return Output;

What are your thoughts? Is it a good idea to do something like this as it makes it more difficult to decode?

Only issue comes down to longer strings... as I just found out

Depends on your purpose of encryption, for people trying to hack, base64 is very easily recognized and is easily deciphered.

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

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
This is a horrible idea, you add >=1/3 to output size every iteration, and yet this is not "encryption" by any definition whatsoever.
 
S

Shawn Shipton

Guest
This is a horrible idea, you add >=1/3 to output size every iteration, and yet this is not "encryption" by any definition whatsoever.
Not to split hairs but "horrible idea" is dependant on its purpose, for the purpose of "secure" encryption absolutely a horrible idea, but the definition of encryption is to encode then decode, which is exactly what base64 does.

If you are just trying to transfer data and just want to keep honest people, honest, and don't care if they can actually dig to get the data, this is fine as it is an easy way and a built in function of GMS to change the data without much effort.

But, if you are trying to keep people from seeing or manipulating the data, you're going to have to do something more secure.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Not to split hairs but "horrible idea" is dependant on its purpose
"horrible idea" was in relation of output size. Let me explain,
8 bytes of input produce 76 bytes of output
16 bytes of input produce 820 bytes of output
24 bytes of input produce 8268 bytes of output
32 bytes of input produce 82676 of output (see where this is going yet?)
40 bytes of input produce 825.8 KB of output (and take 0.35s to encode)
48 bytes of input produce 8.25MB of output (and take 2.3s to encode)
56 bytes of input produce 82MB of output (and take 25s to encode)
64 bytes of input hard crash your application with an out of memory error (supposedly because it's ~825MB of output).
If you don't care about security, you may as well settle with a single pass of base64 encoding instead of doing dangerous manipulations.
 
S

Shawn Shipton

Guest
"horrible idea" was in relation of output size. Let me explain,
8 bytes of input produce 76 bytes of output
16 bytes of input produce 820 bytes of output
24 bytes of input produce 8268 bytes of output
32 bytes of input produce 82676 of output (see where this is going yet?)
40 bytes of input produce 825.8 KB of output (and take 0.35s to encode)
48 bytes of input produce 8.25MB of output (and take 2.3s to encode)
56 bytes of input produce 82MB of output (and take 25s to encode)
64 bytes of input hard crash your application with an out of memory error (supposedly because it's ~825MB of output).
If you don't care about security, you may as well settle with a single pass of base64 encoding instead of doing dangerous manipulations.
I agree then and to add, going through the iterations doesn't help security either, it won't take much to figure out how to reverse the process.
 
Top