Implemented in Javascript. Does only work for odd number of required secrets.