Euclidean algorithm
Decoding based on extended Euclidean algorithm.