Skip to content

Instantly share code, notes, and snippets.

View ttaubert's full-sized avatar

Tim Taubert ttaubert

View GitHub Profile
#include <stdint.h>
// 0xff if MSB(x) = 1 else 0x00
uint8_t msb(uint8_t x) {
return 0 - (x >> (8 * sizeof(x) - 1));
}
// 0xff if a >= b else 0x00
uint8_t nz(uint8_t x) {
return ~msb(~x & (x - 1));
#include <stdint.h>
uint8_t add(uint8_t a, uint8_t b) {
uint8_t sum = a + b;
return sum < a ? UINT8_MAX : sum;
}
@ttaubert
ttaubert / onion-gen.js
Created November 2, 2014 13:14
Generating custom .onion names with the WebCrypto API
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/*
* thirty-two
* https://github.com/chrisumbel/thirty-two
*
@ttaubert
ttaubert / rc4.js
Last active August 29, 2015 14:08
RC4 in (almost) a tweet
function*r(k){t=x=>(y=x%n)in s?s[y]:y;w=_=>t((s[i%n]=t(j+=f=t(i++)))+(s[j%n]=f));for(n=256,s=[i=j=0];i<n;)w(j+=k[i%k.length]);for(j=0,i=1;;)yield w()}
// A raw RC4 stream.
// Works in Firefox only (needs lots of ES6).
// 150 chars
// Usage:
for (var b of r([65,65,65])) {
console.log(b);
}

Keybase proof

I hereby claim:

  • I am ttaubert on github.
  • I am ttaubert (https://keybase.io/ttaubert) on keybase.
  • I have a public key whose fingerprint is B1CB F850 F25E 7B7B 8C91 9AA6 4DD9 6198 4B92 E4F2

To claim this, I am signing this object: