Skip to content

Instantly share code, notes, and snippets.

View rndme's full-sized avatar

dandavis rndme

View GitHub Profile
®‼⁉™ℹ↔↕↖↗↘↙↩↪⌚⌛⌨⏏⏩⏪⏫⏬⏭⏮⏯⏰⏱⏲⏳▪▫▶◀◻◼◽◾☀☁☂☃☄☎☑☔☕☘☝☠☢☣☦☪☮☯☸☹☺♀♂♈♉♊♋♌♍♎♏♐♑♒♓♟♠♣♥♦♨♻♾♿⚒⚓⚔⚕⚖⚗⚙⚛⚜⚠⚡⚪⚫⚰⚱⚽⚾⛄⛅⛈⛎⛏⛑⛓⛔⛩⛪⛰⛱⛲⛳⛴⛵⛷⛸⛹⛹️‍♀️⛹️‍♂️⛺⛽✂✅✈✉✊✋✌✍✏✒✔✖✝✡✨✳✴❄❇❌❎❓❔❕❗❣❤➕➖➗➡➰➿⤴⤵⬅⬆⬇⬛⬜⭐⭕〰〽🌀🌁🌂🌃🌄🌅🌆🌇🌈🌉🌊🌋🌌🌍🌎🌏🌐🌑🌒🌓🌔🌕🌖🌗🌘🌙🌚🌛🌜🌝🌞🌟🌠🌰🌱🌲🌳🌴🌵🌶🌷🌸🌹🌺🌻🌼🌽🌾🌿🍀🍁🍂🍃🍄🍅🍆🍇🍈🍉🍊🍋🍌🍍🍎🍏🍐🍑🍒🍓🍔🍕🍖🍗🍘🍙🍚🍛🍜🍝🍞🍟🍠🍡🍢🍣🍤🍥🍦🍧🍨🍩🍪🍫🍬🍭🍮🍯🍰🍱🍲🍳🍴🍵🍶🍷🍸🍹🍺🍻🍼🎀🎁🎂🎃🎄🎅🎆🎇🎈🎉🎊🎋🎌🎍🎎🎏🎐🎑🎒🎓🎠🎡🎢🎣🎤🎥🎦🎧🎨🎩🎪🎫🎬🎭🎮🎯🎰🎱🎲🎳🎴🎵🎶🎷🎸🎹🎺🎻🎼🎽🎾🎿🏀🏁🏂🏃🏃‍♀️🏃‍♂️🏄🏄‍♀️🏄‍♂️🏅🏆🏇🏈🏉🏊🏊‍♀️🏊🏠🏡🏢🏣🏤🏥🏦🏧🏨🏩🏪🏫🏬🏭🏮🏯🏰‍🌈‍☠️🐀🐁🐂🐃🐄🐅🐆🐇🐈🐉🐊🐋🐌🐍🐎🐏🐐🐑🐒🐓🐔🐕🐖🐗🐘🐙🐚🐛🐜🐝🐞🐟🐠🐡🐢🐣🐤🐥🐦🐧🐨🐩🐪🐫🐬🐭🐮🐯🐰🐱🐲🐳🐴🐵🐶🐷🐸🐹🐺🐻🐼🐽🐾👀👂👃👄👅👆👇👈👉👊👋👌👍👎👏👐👑👒👓👔👕👖👗👘👙👚👛👜👝👞👟👠👡👢👣👤👥👦👧👨👨‍⚕️👨‍⚖️👨‍✈️👨‍❤️‍👨👨‍❤️‍💋‍👨👨‍🌾👨‍🍳👨‍🎓👨‍🎤👨‍🎨👨‍🏫👨‍🏭👫👬👭👮👮‍♀️👮‍♂️👯👯‍♀️👯‍♂️👰👱👱‍♀️👱‍♂️👲👳👳‍♀️👳‍♂️👴👵👶👷👷‍♀️👷‍♂️👸👹👺👻👼👽👾👿💀💁💁‍♀️💁‍♂️💂💂‍♀️💂‍♂️💃💄💅💆💆‍♀️💆‍♂️💇💇‍♀️💇‍♂️💈💉💊💋💌💍💎💏💐💑💒💓💔💕💖💗💘💙💚💛💜💝💞💟💠💡💢💣💤💥💦💧💨💩💪💫💬💭💮💯💰💱💲💳💴💵💶💷💸💹💺💻💼💽💾💿📀📁📂📃📄📅📆📇📈📉📊📋📌📍📎📏📐📑📒📓📔📕📖📗📘📙📚📛📜📝📞📟📠📡📢📣📤📥📦📧📨📩📪📫📬📭📮📯📰📱📲📳📴📵📶📷📹📺📻📼🔀🔁🔂🔃🔄🔅🔆🔇🔈🔉🔊🔋🔌🔍🔎🔏🔐🔑🔒🔓🔔🔕🔖🔗🔘🔙🔚🔛🔜🔝🔞🔟🔠🔡🔢🔣🔤🔥🔦🔧🔨🔩🔪🔫🔬🔭🔮🔯🔰🔱🔲🔳🔴🔵🔶🔷🔸🔹🔺🔻🔼🔽🕐🕑🕒🕓🕔🕕🕖🕗🕘🕙🕚🕛🕜🕝🕞🕟🕠🕡🕢🕣🕤🕥🕦🕧♀️♂️🗻🗼🗽🗾🗿😀😁😂😃😄😅😆😇😈😉😊😋😌😍😎😏😐😑😒😓😔😕😖😗😘😙😚😛😜😝😞😟😠😡😢😣😤😥😦😧😨😩😪😫😬😭😮😯😰😱😲😳😴😵😶😷😸😹😺😻😼😽😾😿🙀🙅🙅‍♀️🙅‍♂️🙆🙆‍♀️🙆‍♂️🙇🙇‍♀️🙇‍♂️🙈🙉🙊🙋🙋‍♀️🙋‍♂️🙌🙍🙍‍♀️🙍‍♂️🙎🙎‍♀️🙎‍♂️🙏🚀🚁🚂🚃🚄🚅🚆🚇🚈🚉🚊🚋🚌🚍🚎🚏🚐🚑🚒🚓🚔🚕🚖🚗🚘🚙🚚🚛🚜🚝🚞🚟🚠🚡🚢🚣🚣‍♀️🚣‍♂️🚤🚥🚦🚧🚨🚩
function copy(str){
var inp = document.createElement("textarea");
inp.style.position="fixed";
document.body.appendChild(inp);
inp.value=str;
inp.select();
document.execCommand("Copy");
inp.remove();
}
@rndme
rndme / hashcrypt.js
Last active November 1, 2018 18:11
Symmetric encryption using hash function and key derivation
function hashCrypt(key, plain, hasher, workFactor=1) { // hasher is any sync string-output hash function
var len=plain.length, keyLen = key.length, keyOrig = key,
// calculate derivation count based on deterministic factors from the inputs:
mx = hasher(key).split("").map((a, b)=> a.charCodeAt(0) + b).reduce((a, b)=> a + b, 0) * workFactor;
// derive firstly for some hardness using cpu and ram hungry calculations:
for(let i = 0; i < mx; i++) key = hasher(key.repeat( ((i+len) % ((workFactor || 1) * 4))+1 ));
// expand key to needed length by appending re-hashing (with counters):
@rndme
rndme / spritzstream.js
Last active July 26, 2016 15:24
given a seed value "iv" (optional), returns a deterministic string of pseudo-random hex values of length "chars"
// public domain, based on https://www.schneier.com/blog/archives/2014/10/spritz_a_new_rc.html
function spritzStream(chars, iv) {
var s = [], key=iv || (Date.now() / (performance.now()*1000)).toString(36) + (chars/Math.random()),
j = 0,
w = 17,
k = 0,
res = [],
l = Math.ceil(key.length/2),
m = chars,
@rndme
rndme / rc4stream.js
Created July 26, 2016 07:36
given a seed value "iv" (optional), returns a deterministic string of pseudo-random hex values of length "chars"
function rc4stream(chars, iv) {
var s = [], key=iv || (Date.now() / (performance.now()*1000)).toString(36) + (chars/Math.random()),
j = 0,
x, res = [],
i, j, y, l = key.length,
m = Math.ceil(chars/2);
for(i = 0; i < 256; i++) s[i] = i;
for(i = 0; i < 256; i++) {
j = (j + s[i] + key.charCodeAt(i % l)) % 256;
@rndme
rndme / sha3stream.js
Last active July 26, 2016 07:55
given a seed value "iv" (optional), returns a deterministic string of pseudo-random hex values of length "chars"
function stream(chars, iv){ // requires https://github.com/emn178/js-sha3/
var buff="", i=0;
iv= sha3_512(iv || (Date.now() / (performance.now()*1000)).toString(36) + (chars/Math.random()));
while(buff.length < chars) buff+= iv = sha3_256(++i + iv);
return buff.slice(0, chars);
}
//ex:
// stream(500, "this is not a great iv");
@rndme
rndme / nonce maker.js
Last active July 26, 2016 01:22
a fast clock times a slow clock and uses a factor of the difference to build a un-predictable 36 alphabet string
function nonce(chars){
var b="", round, last;
while(true){
var round= (Date.now() / (performance.now()*1000)).toString(36).split(".").pop().slice(2, -2);
if(round!=last) b+= round;
if(b.length > chars) break;
last=round;
}
return b.slice(-chars);
}
@rndme
rndme / derive.js
Last active July 6, 2016 02:18
key derivation using sha3 and variable loop count
/* password derivation that forces a re-creation of this routine by making slight mods to a normal hash-based kdf:
requires https://github.com/emn178/js-sha3
Example timings on a i7 in chrome:
cost ms
1 - 108
2 - 408
3 - 1067
4 - 2351
5 - 3927
function getSnapshot(callback) {
"use strict";
callback = callback || Boolean;
var canvas = document.createElement("canvas"),
ctx = canvas.getContext("2d"),
webkit = false,
moz = false,
v = null,
W = 800,
H = 600,
function salad(numbers) { // word salad function for making (hopefully) human-memorable hashes for 64 digit strings (adapt as needed)
var r = "ability|able|about|above|accept|access|according|account|achieve|across|act|action|activity|actually|add|addition|admit|advantage|advice|affair|affect|after|again|against|age|ago|agree|agreement|air|all|allow|almost|along|already|also|although|always|among|amount|analysis|and|animal|announce|another|answer|any|anyone|anything|anyway|appear|application|apply|approach|appropriate|area|argue|argument|arm|army|around|arrive|art|ask|aspect|association|assume|attempt|attention|attitude|authority|available|avoid|award|aware|away|baby|back|bad|bank|base|basic|basis|bear|because|become|bed|before|begin|behavior|behind|believe|benefit|better|between|beyond|big|bill|bit|black|blood|board|body|book|both|box|boy|break|bring|brother|build|building|business|but|buy|call|campaign|can|capital|car|care|carry|case|catch|cause|cell|central|center|century|certain|certainly|chance|change|c