modInverse & powMod

Salih Dincer salihdb at hotmail.com
Sat Jan 11 06:42:32 UTC 2025


On Saturday, 8 June 2024 at 12:28:43 UTC, Salih Dincer wrote:
> Is PR required? Why not modInverse too!

```d
long extendedEuclidean(long a, long b) {
     long old_r = a, r = b;
     long old_s = 1, s = 0;
     long old_t = 0, t = 1;

     while (r != 0) {
         long quotient = old_r / r;
         long temp = r;
         r = old_r - quotient * r;
         old_r = temp;

         temp = s;
         s = old_s - quotient * s;
         old_s = temp;

         temp = t;
         t = old_t - quotient * t;
         old_t = temp;
     }

     if (old_s < 0) {
         old_s += b;
     }

     return old_s;
}
```
Apparently no one is as interested in RSA as I am, so I just 
wanted to paste the standalone algorithm here for reference.

SDB at 79




More information about the Digitalmars-d-learn mailing list