This file contains hidden or 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
### RSA textbook-ish walkthrough ### | |
# This is WORK IN PROGRESS. | |
# Intend to cover: | |
# -- "RSA uses numbers, not words?" (DONE) | |
# -- RSA ACTUAL MATH FORMULA (DONE) | |
# -- Hybrid encryption (TODO) | |
# -- Asymmetric padding (TODO) | |
# -- Forward secrecy, part 1 (TODO) | |
# -- Encapsulation protocols (TODO) |
This file contains hidden or 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
await (n => | |
fetch('https://qrng.anu.edu.au/API/jsonI.php?' + new URLSearchParams({length: n, type: 'uint8'})) | |
.then(response => {if (!response.ok) {throw response}; return response.json();}) | |
.then(result => new Uint8Array(result['data'])) | |
) | |
(32); | |
// https://quantumnumbers.anu.edu.au/pricing | |
await (key => | |
(n => |
This file contains hidden or 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
/** | |
* Get an element by XPath. | |
* Includes workaround for browser bug not allowing SVG elements to be selected; use the virtual "_" prefix to reference the context node's namespace. | |
* @param {string} expression - A string representing the XPath to be evaluated. | |
* @param {Node|Document} [contextNode] - The context node. | |
* @param {XPathEvaluator|Document} [document] - The document via which evaluate() will be called. Defaults to the context node's document, if specified; otherwise globalThis.document. Required if context node and globalThis.document are both absent. | |
* @param {boolean} [ordered=true] - Whether to return the "first" node selected by the expression. If false, allows the XPath engine to return an arbitrary node selected by the expression. | |
* @returns {?Node} | |
*/ | |
export function getElementByXPath(expression, contextNode, document, ordered=true) { |
This file contains hidden or 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 bn_powMod(a, e, m) { | |
// h/t https://umaranis.com/2018/07/12/calculate-modular-exponentiation-powermod-in-javascript-ap-n/ | |
if (m === 1n) | |
return 0n; | |
if (e < 0n) | |
return bn_powMod(bn_modInv(a, m), -e, m); | |
for (var b = 1n; e; e >>= 1n) { | |
if (e % 2n === 1n) | |
b = (b * a) % m; | |
a = (a * a) % m; |
This file contains hidden or 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
#!/usr/bin/env python3 | |
import hashlib | |
b = 256 | |
q = 2**255 - 19 | |
l = 2**252 + 27742317777372353535851937790883648493 | |
def H(m): | |
return hashlib.sha512(m).digest() |
This file contains hidden or 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
#!/bin/sh | |
otheruser="$(id -nu 1000)" | |
xhost "+SI:localuser:${otheruser}" | |
if pulseaudio --check; then | |
pax11publish -S "/run/user/$(id -u)/pulse/native" -e | |
setfacl -m "u:${otheruser}:x" "/run/user/$(id -u)" "/run/user/$(id -u)/pulse" | |
setfacl -m "u:${otheruser}:rw" "/run/user/$(id -u)/pulse/native" | |
setfacl -m "m::rwx" "/run/user/$(id -u)/pulse" |
This file contains hidden or 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
perl -0pe 's/^\s*(\S+)\s\[(.*?)\s*\]:\s+(.*)\n\s*(.*)/\1\t\2\t\3\t\4/gm' /proc/asound/cards # | cut -f"${fieldIndex-1}" | |
# fieldIndex: 1=ID; 2=Type; 3=Name; 4=Description |
This file contains hidden or 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
// James Edington <[email protected]> | |
// ht https://wunkolo.github.io/post/2020/05/pclmulqdq-tricks/ | |
// h/t https://en.wikipedia.org/wiki/Carry-less_product | |
function clmul(a, b) { | |
const ONE = Object.getPrototypeOf(a).constructor(1) | |
const a_bit_length = a.toString(2).length; | |
let result = Object.getPrototypeOf(ONE).constructor(0); | |
for ( let i = 0 ; i < a_bit_length ; i++ ) { | |
result ^= b*(a & ONE<<i); |
This file contains hidden or 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
from operator import eq as _eq | |
from itertools import starmap as _starmap, chain as _chain, repeat as _repeat | |
def _istartswith(a, b): | |
""" | |
Returns True if every element of b is equal to the zip-corresponding element of a; | |
returns False otherwise, including in the event that a has fewer elements than b. | |
""" | |
return all(_starmap(_eq, zip(_chain(a, _starmap(object, _repeat(()))), b))) |
This file contains hidden or 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
import functools | |
from .. import NORMALIZE_FUNC, EXPENSIVE_API_CALL | |
@(lambda t: lambda f: functools.wraps(f)(lambda x: f(t(x))))(NORMALIZE_FUNC) | |
@functools.lru_cache | |
def f(x): | |
return EXPENSIVE_API_CALL(x) |