Skip to content

Instantly share code, notes, and snippets.

<?php
/* Strip out un-supported HTML tags */
$content = strip_tags($content, '<strong><em><del><li><code><pre>');
/* Properly format message */
$content = str_replace(array('<strong>', '</strong>'), array('*', '*'), $content);
$content = str_replace(array('<em>', '</em>'), array('_', '_'), $content);
$content = str_replace(array('<del>', '</del>'), array('~', '~'), $content);
$content = str_replace(array('<li>', '</li>'), array('', ''), $content);
@creyer
creyer / Hash Ladders for Shorter Lamport Signatures.md
Created September 6, 2017 16:10 — forked from karlgluck/Hash Ladders for Shorter Lamport Signatures.md
I describe a method for making Lamport signatures take up less space. I haven't seen anyone use hash chains this way before, so I think it's pretty cool.

What's this all about?

Digital cryptography! This is a subject I've been interested in since taking a class with Prof. Fred Schneider back in college. Articles pop up on Hacker News fairly often that pique my interest and this technique is the result of one of them.

Specifically, this is about Lamport signatures. There are many signature algorithms (ECDSA and RSA are the most commonly used) but Lamport signatures are unique because they are formed using a hash function. Many cryptographers believe that this makes them resistant to attacks made possible by quantum computers.

How does a Lamport Signature work?

ּ_בּ
בּ_בּ
טּ_טּ
כּ‗כּ
לּ_לּ
מּ_מּ
סּ_סּ
תּ_תּ
٩(×̯×)۶
٩(̾●̮̮̃̾•̃̾)۶
Answers http://stackoverflow.com/questions/10373318/mixing-in-a-trait-dynamically.
Compile as follows:
scalac Common_1.scala Macros_2.scala
scalac Common_1.scala Test_3.scala -cp <path to the result of the previous compilation>
Tested in 2.10.0-M3, will most likely not compile by the time 2.10.0 final is released, because we're actively rehashing the API.
However the principles will remain the same in the final release, so the concept itself is okay.
upd. Code updated for 2.10.0-M7.
upd. Code updated for 2.10.0-RC1.
@creyer
creyer / gist:74f77af01dce07daac34
Created December 10, 2014 17:04
custom cache with Monifu
import monifu.concurrent.atomic.AtomicInt
import monifu.reactive.Observable
import monifu.reactive.channels.PublishChannel
import monifu.reactive.subjects.PublishSubject
import monifu.reactive._
import scala.concurrent.{Future}
import concurrent.duration._
import monifu.concurrent.Implicits._
import monifu.reactive.Ack.Continue
@creyer
creyer / gist:5f0252282a759397e825
Created December 10, 2014 15:30
cache with monifu
object Main extends App {
//create a cache, hot observable
val cache = Observable.interval(15.second).flatMap (_ => DBEmulator.read()).publish()
//extract elements from cache at fixed intervals
cache.sampleRepeated(1.second).doWork(a => println(s"${System.currentTimeMillis()/1000} I prove works: $a")).subscribe()
cache.sampleRepeated(3.second).doWork(a => println(s"${System.currentTimeMillis()/1000} III prove works: $a")).subscribe()
cache.sampleRepeated(5.second).doWork(a => println(s"${System.currentTimeMillis()/1000} V prove works: $a")).subscribe()
//connect to the hot observable, start the stream
val subscription = cache.connect()
}