It's quite elementary, my dear Watson.

See GitHub for documentation and source code.