Algorith from Handbook of Applied Cryptography (Discrete Mathematics and Its Applications)