Skip to content

Instantly share code, notes, and snippets.

@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);
@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))
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);
/*
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;
@rfl890
rfl890 / openssl-build-static-msvc.c
Created June 24, 2023 16:22
Fix build failure errors on MSVC for OpenSSL
#pragma comment (lib, "crypt32")
#pragma comment(lib, "ws2_32")
#pragma comment(lib, "user32")
#pragma comment(lib, "advapi32")
@rfl890
rfl890 / hmac.c
Created July 3, 2023 15:06
Shitty openssl hmac
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#pragma comment (lib, "crypt32")
#pragma comment(lib, "ws2_32")
@rfl890
rfl890 / aes.c
Last active July 9, 2023 17:20
OpenSSL AES-256-CBC encryption/decryption with HMAC
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include <immintrin.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/kdf.h>
#include <openssl/rand.h>
@rfl890
rfl890 / better-emojis.js
Created July 24, 2023 15:21
Noto Color Emoji Userscript
// ==UserScript==
// @name Better emojis
// @namespace Violentmonkey Scripts
// @match *://*/*
// @grant none
// @version 1.0
// @run-at document-end
// @author -
// @description Replaces the default emoji font on your device. Works with newer browsers (Chrome & Edge 98+, Firefox 107+, Opera 100+)
// ==/UserScript==
@rfl890
rfl890 / aes256-ni.c
Last active August 6, 2023 22:32
AES-256 how to with AES-NI
#include <wmmintrin.h>
#include <stdio.h>
#include <string.h>
static __m128i aes_256_key_expansion_1(__m128i key,
__m128i keygened)
{
keygened = _mm_shuffle_epi32(keygened, _MM_SHUFFLE(3, 3, 3, 3));
key = _mm_xor_si128(key, _mm_slli_si128(key, 4));
key = _mm_xor_si128(key, _mm_slli_si128(key, 4));
@rfl890
rfl890 / lua-unicode-input.lua
Last active December 13, 2023 00:30
Hacky way of obtaining Unicode input as UTF-8 in Lua(JIT)
local ffi = require("ffi")
ffi.cdef[[
struct _iobuf {
char *_ptr;
int _cnt;
char *_base;
int _flag;
int _file;
int _charbuf;