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
""" | |
Rough implementations of patience sorts (p3 sort) as shown in | |
https://www.microsoft.com/en-us/research/publication/patience-is-a-virtue-revisiting-merge-and-sort-on-modern-processors/. | |
Note that performance benchmarks won't be valid, since the data structures used (e.g. deque) don't take advantage of memory locality | |
in the same way that an implementation of cache-local linked memory blocks would. | |
""" | |
from collections import deque | |
from binary_search import binary_search |
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
# Merkle Tree implementation in Python | |
from collections import deque | |
from hashlib import sha3_224 | |
class MerkleNode: | |
def __init__(self, children: list = None, value: str = None): | |
assert not (children and value is not None) and (children or value is not None), 'requires either children or value' |
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
const crypto = require('crypto'); | |
let bytes = crypto.randomBytes(16); | |
// using bit operations (unnecessary) to get individual digits | |
console.log([...bytes].map(v => (v >> 4).toString(16) + (v & 15).toString(16)).join('')); | |
// you can directly convert the byte to hexadecimal instead, making sure to pad digits. | |
console.log([...bytes].map(v => v.toString(16).padStart(2, '0')).join('')); | |
// even better, directly convert the buffer to hex | |
console.log(bytes.toString('hex')); |
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
/* | |
* The goal of this gist is to demonstrate how the RSA cryptosystem works | |
* with a toy implementation. | |
*/ | |
// must have both primes to efficiently compute the private key. | |
function computePrivateKey(p1, p2, pub) { | |
// Use Euler's theorem to calculate phi(p1p2) => phi(p1) * phi(p2). | |
/* |