I did something quite like this years ago that now has implementations in many programming languages:<p><a href="https://arxiv.org/html/0901.4016" rel="nofollow">https://arxiv.org/html/0901.4016</a><p><a href="https://github.com/dsw/proquint" rel="nofollow">https://github.com/dsw/proquint</a>