A naive reference implementation in php