This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function useState(value){ // designed after https://reactjs.org/docs/hooks-intro.html demo | |
var o = useState.state || (useState.state = new Map()); | |
if(o.has(arguments.callee.caller)){ // not first time? | |
return o.get(arguments.callee.caller); | |
}else{ | |
// build array of returns, set it, return it | |
var ret = []; | |
[...arguments].map((x, i)=>{ | |
ret.push(x) | |
ret.push(function _updater(val){ ret[(i*2)] = val; }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ip(cb) { | |
with(new RTCPeerConnection) { | |
createDataChannel(0); | |
createOffer(e=> setLocalDescription(e), Date); | |
onicecandidate =e=>{if(e=e.candidate) cb(e.candidate.split(/\s+/)[4])}; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
®‼⁉™ℹ↔↕↖↗↘↙↩↪⌚⌛⌨⏏⏩⏪⏫⏬⏭⏮⏯⏰⏱⏲⏳▪▫▶◀◻◼◽◾☀☁☂☃☄☎☑☔☕☘☝☠☢☣☦☪☮☯☸☹☺♀♂♈♉♊♋♌♍♎♏♐♑♒♓♟♠♣♥♦♨♻♾♿⚒⚓⚔⚕⚖⚗⚙⚛⚜⚠⚡⚪⚫⚰⚱⚽⚾⛄⛅⛈⛎⛏⛑⛓⛔⛩⛪⛰⛱⛲⛳⛴⛵⛷⛸⛹⛹️♀️⛹️♂️⛺⛽✂✅✈✉✊✋✌✍✏✒✔✖✝✡✨✳✴❄❇❌❎❓❔❕❗❣❤➕➖➗➡➰➿⤴⤵⬅⬆⬇⬛⬜⭐⭕〰〽🌀🌁🌂🌃🌄🌅🌆🌇🌈🌉🌊🌋🌌🌍🌎🌏🌐🌑🌒🌓🌔🌕🌖🌗🌘🌙🌚🌛🌜🌝🌞🌟🌠🌰🌱🌲🌳🌴🌵🌶🌷🌸🌹🌺🌻🌼🌽🌾🌿🍀🍁🍂🍃🍄🍅🍆🍇🍈🍉🍊🍋🍌🍍🍎🍏🍐🍑🍒🍓🍔🍕🍖🍗🍘🍙🍚🍛🍜🍝🍞🍟🍠🍡🍢🍣🍤🍥🍦🍧🍨🍩🍪🍫🍬🍭🍮🍯🍰🍱🍲🍳🍴🍵🍶🍷🍸🍹🍺🍻🍼🎀🎁🎂🎃🎄🎅🎆🎇🎈🎉🎊🎋🎌🎍🎎🎏🎐🎑🎒🎓🎠🎡🎢🎣🎤🎥🎦🎧🎨🎩🎪🎫🎬🎭🎮🎯🎰🎱🎲🎳🎴🎵🎶🎷🎸🎹🎺🎻🎼🎽🎾🎿🏀🏁🏂🏃🏃♀️🏃♂️🏄🏄♀️🏄♂️🏅🏆🏇🏈🏉🏊🏊♀️🏊🏠🏡🏢🏣🏤🏥🏦🏧🏨🏩🏪🏫🏬🏭🏮🏯🏰🌈☠️🐀🐁🐂🐃🐄🐅🐆🐇🐈🐉🐊🐋🐌🐍🐎🐏🐐🐑🐒🐓🐔🐕🐖🐗🐘🐙🐚🐛🐜🐝🐞🐟🐠🐡🐢🐣🐤🐥🐦🐧🐨🐩🐪🐫🐬🐭🐮🐯🐰🐱🐲🐳🐴🐵🐶🐷🐸🐹🐺🐻🐼🐽🐾👀👂👃👄👅👆👇👈👉👊👋👌👍👎👏👐👑👒👓👔👕👖👗👘👙👚👛👜👝👞👟👠👡👢👣👤👥👦👧👨👨⚕️👨⚖️👨✈️👨❤️👨👨❤️💋👨👨🌾👨🍳👨🎓👨🎤👨🎨👨🏫👨🏭👫👬👭👮👮♀️👮♂️👯👯♀️👯♂️👰👱👱♀️👱♂️👲👳👳♀️👳♂️👴👵👶👷👷♀️👷♂️👸👹👺👻👼👽👾👿💀💁💁♀️💁♂️💂💂♀️💂♂️💃💄💅💆💆♀️💆♂️💇💇♀️💇♂️💈💉💊💋💌💍💎💏💐💑💒💓💔💕💖💗💘💙💚💛💜💝💞💟💠💡💢💣💤💥💦💧💨💩💪💫💬💭💮💯💰💱💲💳💴💵💶💷💸💹💺💻💼💽💾💿📀📁📂📃📄📅📆📇📈📉📊📋📌📍📎📏📐📑📒📓📔📕📖📗📘📙📚📛📜📝📞📟📠📡📢📣📤📥📦📧📨📩📪📫📬📭📮📯📰📱📲📳📴📵📶📷📹📺📻📼🔀🔁🔂🔃🔄🔅🔆🔇🔈🔉🔊🔋🔌🔍🔎🔏🔐🔑🔒🔓🔔🔕🔖🔗🔘🔙🔚🔛🔜🔝🔞🔟🔠🔡🔢🔣🔤🔥🔦🔧🔨🔩🔪🔫🔬🔭🔮🔯🔰🔱🔲🔳🔴🔵🔶🔷🔸🔹🔺🔻🔼🔽🕐🕑🕒🕓🕔🕕🕖🕗🕘🕙🕚🕛🕜🕝🕞🕟🕠🕡🕢🕣🕤🕥🕦🕧♀️♂️🗻🗼🗽🗾🗿😀😁😂😃😄😅😆😇😈😉😊😋😌😍😎😏😐😑😒😓😔😕😖😗😘😙😚😛😜😝😞😟😠😡😢😣😤😥😦😧😨😩😪😫😬😭😮😯😰😱😲😳😴😵😶😷😸😹😺😻😼😽😾😿🙀🙅🙅♀️🙅♂️🙆🙆♀️🙆♂️🙇🙇♀️🙇♂️🙈🙉🙊🙋🙋♀️🙋♂️🙌🙍🙍♀️🙍♂️🙎🙎♀️🙎♂️🙏🚀🚁🚂🚃🚄🚅🚆🚇🚈🚉🚊🚋🚌🚍🚎🚏🚐🚑🚒🚓🚔🚕🚖🚗🚘🚙🚚🚛🚜🚝🚞🚟🚠🚡🚢🚣🚣♀️🚣♂️🚤🚥🚦🚧🚨🚩 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 |