Skip to content

Instantly share code, notes, and snippets.

@bryc
bryc / cyrb32.c
Last active February 9, 2018 00:27
A simple but usable checksum/hash algorithm, in C.
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
unsigned char *data;
int len = 0;
int cyrb32() {
uint32_t i, tmp, sum = 0xbf3931a8;
for(i = 32; i < len; i++) {
/*
a mockup of a fileformat with a 8 byte header. 56-bit magic, 8-bit version code, and 64-bit hash.
*/
var data = [250,222,222,175,98,83,80,0,149,227,98,114,223,2,65,139,212,54,64,54,169,172,160,90,58,126,203,87,217,240,53,186,160,226,221,133,70,56,95,24,49,66,201,41,182,75,120,164,236,222,80,145,147,117,15,88,219,136,158,2,20,70,140,78,163,103,32,199,173,219,175,24,97,78,33,93,215,188,212,50,218,155,63,171,40,68,17,134,244,173,170,70,180,159,32,245,135,233,57,203,196,84,18,249,120,73,72,71,223,101,226,87,42,132,104,173,25,242,197,218,55,191,232,94,192,124,90,38,130,209,31,191,73,175,162,149,144,23,144,228,157,185,200,43,59,215,220,70,173,60,188,142,168,51,132,136,82,197,155,28,157,175,122,82,138,217,234,9,24,64,128,54,248,145,159,140,63,244,94,168,188,196,252,32,159,36,223,9,154,195,52,215,181,53,168,184,107,167,233,180,210,240,211,64,230,41,117,26,64,97,101,137,182,14,0,84,201,78,142,38,219,37,110,27,125,58,187,170,101,208,21,58,211,245,119,11,118,33,74,61,23,197,29,34,155,132,182,48,37,20,89,44,106,253,1
@bryc
bryc / base.js
Last active December 13, 2018 08:16
// Arbitrary precision base conversion, WIP
function baxx(str, src_base, dst_base) {
var number = [], output = "", res = [], quotient, remainder;
var charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
//decode
for(var i = 0; i < str.length; i++) number[i] = charset.indexOf(str[i]);
while (number.length) {
// divide successive powers of dst_base
quotient = [], remainder = 0;
@bryc
bryc / lzjb.js
Last active October 18, 2019 08:22
proof of concept tiny compression
// tiny simple hash (TSH)
TSH=s=>{for(var i=0,h=6,c=5;i<s.length;)h=Math.imul(h^s[i],9**9),c=Math.imul(c^s[i++],7**9);return 2**32*(2097151&(c^c>>>9))+(h^h>>>9)}
// LZB minified 512 bytes.
LZB={e:(e,f)=>{for(var r,l,o,i,s,a=0,g=0,h=128,n=[],t=e.length;a<t;)if(256==(h<<=1)&&(h=1,l=g,f[g++]=0),a>t-3)f[g++]=e[a++];else if(i=a-n[s=66*e[a]^33*e[a+1]^e[a+2]]&1023,n[s]=a,(r=a-i)!=a&&e[a]==e[r]&&e[a+1]==e[r+1]&&e[a+2]==e[r+2]){for(o=3;o<66&&e[a+o]==e[r+o];o++);a+=o,f[l]|=h,f[g++]=o-3<<2|i>>8,f[g++]=i&255}else f[g++]=e[a++]},d:(e,f)=>{for(var r,l,o,i=0,s=0,a=128;i<e.length;)if(256==(a<<=1)&&(a=1,l=e[i++]),l&a)for(r=s-(1023&(e[i]<<8|e[i+1])),o=3+(e[i]>>2),i+=2;o>0;o--)f[s++]=f[r++];else f[s++]=e[i++]}}
var sum = [], packed = [], unpacked = [], data = [0,0,0,0,0,0,0,0,9,0,255,79,127,191,191,191,143,5,4,7,129,0,0,0,0,0,0,0,0,0,3,1,0,0,0,1,0,103,60,84,47,53,27,26,30,2,0,0,0,0,0,0,68,65,7,109,0,0,0,0,0,0,0,0,9,0,255,79,127,191,191,191,143,5,4,7,129,0,0,0,0,0,0,0,0,0,3,1,0,0,0,1,0,103,60,84,47,53,27,26,30,2,0,0,0,0,0,0,68,
@bryc
bryc / Metrics.js
Last active December 18, 2019 22:42
Reading NonClientMetrics and IconMetrics data in C. Access inaccessible variables for modifying the metrics of desktop icons.
/* Just a tool for converting space-delimited decimal values to hex. */
var NonclientMetrics = "88 1 0 0 7 0 0 0 17 0 0 0 17 0 0 0 18 0 0 0 23 0 0 0 240 255 255 255 0 0 0 0 0 0 0 0 0 0 0 0 188 2 0 0 1 0 0 0 0 0 5 0 85 98 117 110 116 117 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 0 0 0 8 0 0 0 253 255 255 255 0 0 0 0 0 0 0 0 0 0 0 0 144 1 0 0 0 0 0 0 0 0 5 0 83 109 97 108 108 32 70 111 110 116 115 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 0 0 0 18 0 0 0 248 255 255 255 0 0 0 0 0 0 0 0 0 0 0 0 144 1 0 0 0 0 0 0 0 0 5 0 85 98 117 110 116 117 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 244 255 255 255 0 0 0 0 0 0 0 0 0 0 0 0 188 2 0 0 1 0 0 0 0 0 5 0 85 98 117 110 116 117 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 235 255 255 255 0 0 0 0 0 0 0 0 0 0 0 0 188 2 0 0 1 0 0 0 0 0 5 0 85 98 117 110 116 117 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 0 0 0";
var IconMetrics = "76 0 0 0 122 0 0 0 46 0 0 0 1 0 0 0 247 255 255 255 0 0 0 0 0 0 0 0 0 0 0 0 144 1
@bryc
bryc / VRC7_patch_guesses.txt
Last active February 3, 2020 06:02
not mine, just a collection
// Patch names
1 Buzzy Bell
2 Guitar
3 Wurly
4 Flute
5 Clarinet
6 Synth
7 Trumpet
8 Organ
9 Bells
<script>
for(rnd=w=>'#'+Math.random().toString(16).slice(-6),i=0;i<99;i++)
document.write(`<div style=background:linear-gradient(0.25turn,${rnd()},${rnd()},${rnd()},${rnd()})></div>`)
</script>
<style>body{background:#222;column-count:3;column-gap:6px}div{height:48;break-inside:avoid}</style>
<!--
background: repeating-linear-gradient(45deg, #3f87a6, #ebf8e1 5%, #f69d3c 20%);
clip-path: polygon(5% 5%, 100% 0%, 100% 75%, 75% 75%, 75% 100%, 50% 75%, 0% 75%);
-->
// some color conversion code i didnt end up using but might as well put somewhere
function hcl2rgb(arr) {
function lab2xyz(t){return t>6/29?t*t*t:6/29*3*(6/29)*(t-4/29)}
function xyz2rgb(x){return 255*(x<=.0031308?12.92*x:1.055*Math.pow(x,1/2.4)-.055)}
var h = arr[0], c = arr[1], l = arr[2];
y = (l+16)/116,
a = Math.cos(h)*c, b = Math.sin(h)*c,
x = isNaN(a)?y:y+a/500, z = isNaN(b)?y:y-b/200;
@bryc
bryc / rc4.js
Last active March 6, 2021 11:26
RC4
function rc4(key, data) {
var output = [], S = [], tmp, i, j = 0;
for (i = 0; i < 256; i++) {
S[i] = i;
}
for (i = 0; i < 256; i++) {
j = (j + S[i] + key[i % key.length]) % 256;
tmp = S[i];
S[i] = S[j];
S[j] = tmp;
@bryc
bryc / alea.js
Last active March 15, 2022 12:01
PRNGs
/*
Optimized Alea
----------------------
Based on Alea by Johannes Baagøe (2010) which is based on MWC by George Marsaglia and Arif Zaman (1991).
Should be fast and pass BigCrush statistical test suite. It's quite fast but the quality is unverified.
Used like so:
var rand = Alea("test123");
rand(); // 0.7390809920616448
rand(); // 0.3916741746943444