Skip to content

Instantly share code, notes, and snippets.

@gnysek
Created August 6, 2023 22:51
Show Gist options
  • Save gnysek/b1a247af0d202af2f87ce4f5d84cee2f to your computer and use it in GitHub Desktop.
Save gnysek/b1a247af0d202af2f87ce4f5d84cee2f to your computer and use it in GitHub Desktop.
buffedecrypt.gml
// 39dll <3
function bufferencrypt(_key, b = global.buffer) {
bufferdecrypt(_key, b);
}
function bufferdecrypt(_key, _buff = global.buffer) {
var keylen = min(string_length(_key), 256);
if (keylen < 0) return false;
var i, j ,t, temp, xx;
var KeyBox = array_create(256, "");
for(i = 0; i < 256; i++) {
KeyBox[i] = chr(i);
}
i = 0; j = 0; t = 0;
for(i = 0; i < 256; i++) {
j = (j + ord(KeyBox[i]) + ord(string_char_at(_key, (i % keylen) + 1))) % 256;
temp = KeyBox[i];
KeyBox[i] = KeyBox[j];
KeyBox[j] = temp;
}
var _tmpBuffer = buffer_create(buffer_get_size(_buff), buffer_fixed, 1);
buffer_copy(_buff, 0, buffer_get_size(_buff), _tmpBuffer, 0);
i = 0; j = 0;
for(xx = 0; xx < buffer_get_size(_tmpBuffer); xx++) {
i = (i + 1) % 256;
j = (j + ord(KeyBox[i])) % 256;
temp = KeyBox[i];
KeyBox[i] = KeyBox[j];
KeyBox[j] = temp;
t = (ord(KeyBox[i]) + ord(KeyBox[j])) % 256;
buffer_poke(_tmpBuffer, xx, buffer_u8, buffer_peek(_tmpBuffer, xx, buffer_u8) ^ ord(KeyBox[t]));
}
buffer_resize(_buff, 0);
buffer_copy(_tmpBuffer, 0, buffer_get_size(_tmpBuffer), _buff, 0);
buffer_delete(_tmpBuffer);
buffer_seek(_buff, buffer_seek_start, 0);
return _buff;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment