On the Inversion Modulo a Power of an Integer
Abstract
Recently, Koc proposed a neat and efficient algorithm for computing \[ x = a-1 pk \] for a prime p based on the exact solution of linear equations using p-adic expansions. The algorithm requires only addition and right shift per step. In the first part of this paper, we design an algorithm that computes \[ x = a-1 nk \] for any integers a, n>1 with (a, n)=1. The algorithm has a motivation from the schoolbook multiplication and achieves both efficiency and generality. The greater flexibility of our algorithm is explored by utilizing the built-in arithmetic of computer architecture, e.g., n=264, and experimental results show significant improvements. This paper also contains some results on modular inverse based on an alternative proof of correctness of Koc algorithm. For the computation of modular inverses when the modulus is a special power of a prime p (i.e., of the form p2s), an efficient algorithm was developed by Dumas and later improved by Hurchalla. These methods are based on Hensel lifting and perform particularly well when p=2 and 2s matches the native bit width of a computer. In the second part of the paper, we present a generalization of these methods to moduli of the form n2s for any integer n>1. The derivation of our algorithm follows from a simple algebraic manipulation.
Turn this paper into a full lesson
ArcXiv compiles a staged curriculum from this paper: 8-12 lessons across beginner → advanced, synthesised section guides, visuals, flashcards, a quiz, exercises, and on-demand deep dives per section. Grounded in the abstract, never invented.