Skip to content

Instantly share code, notes, and snippets.

/*
This is a "rewrite" of isaacCSPRNG by macmcmeans (https://github.com/macmcmeans/isaacCSPRNG)
It has been adapted to use newer JavaScript features. I've
removed some features that I deemed unnecessary,
but you can write them yourselves easily by using
the random() function as you would with Math.random().
*/
class isaacCSPRNG {
#memory;
#accumulator;
local function rol64(x, k)
return (x << k) | (x >> (64 - k));
end
local function xoshiro256ss_step(state)
local result = rol64(state[2] * 5, 7) * 9;
local t = state[2] << 17;
state[3] = state[3] ~ state[1]; state[4] = state[4] ~ state[2]; state[2] = state[2] ~ state[3]; state[1] = state[1] ~ state[4];
state[3] = state[3] ~ t;
state[4] = rol64(state[3], 45);
@rfl890
rfl890 / js-string-split.lua
Last active June 9, 2023 20:15
String.split with JavaScript-like behaviour in Lua
local function js_string_split(s, f)
local offset = 1
local nextOffset = 0
local result = {}
if not string.find(s, f) then
return { s }
end
if f == "" then
for i = 1, #s do
table.insert(result, s:sub(i, i))
@rfl890
rfl890 / btoa-atob-utf8.js
Created May 29, 2023 15:58
btoa and atob with UTF-8 support
function btoaUTF8(data) {
const utf8Data = new TextEncoder().encode(data);
let binaryString = "";
for (let i = 0; i < utf8Data.length; i++) {
binaryString += String.fromCharCode(utf8Data[i]);
}
return btoa(binaryString);
}
function atobUTF8(data) {
const decodedData = atob(data);