This code was written to compute xy mod m for large integers x, y & m. This is a high level description of the code that specifies some internal interfaces and these are some notes that I wrote to myself to guide the design. Here is how to call it.
The little Java program does one of three tricks: Here is a nice collection of tricks that I didn’t use.

I wrote the above code about 2003. Today (2014) I would try the mulq command and use perhaps 62 bits per long word instead of 30 bits per word.