Difficulty : 4 - Just a lot of work. Need to be able to handle VLI
(Very Long Integers)
A VLI algorithm would be a useful addition to our notebook.
If you want, I can supply a VLI algorithm, since I am doing a
project that requires it.
Digital Signatures
On the internet it's possible to forge electronic mail. When you're reading
email, how can you know that it's really from the person it says it's from?
One solution to this is to use digital signatures.
Let H be a cryptographically strong hash function which takes as input an
email message M and outputs a 1024 bit integer H(M). "Cryptographically
strong" means that given a 1024 bit integer x, it is computationally infeasible to
find a
message M such that H(M)=x.
Let p and q be two 512-bit primes, and let n=pq. Every user has his or her
own secret pair of primes, and lets n be public. The signing key K is the
multiplicative inverse of 3 modulo (p-1)(q-1), and is also secret. Then the signature S of
a message M is H(M)^K mod n. To verify the signature S of a message M, a
reader simply computes H(M), and checks that it equals S^3 mod n.
The input will begin with an integer giving the number of messages to be
signed. For each message you will be given H(M), K, and n in decimal, in
that order, with a blank line after each number. Your job is to compute H(M)^K mod n. The
numbers will each be between 0 inclusive and 2^1024 exclusive (n>0). An
example input:
2
5729
8172
8633
179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137215
63618524830875767892200765119824545966949190681255945914405460138734542891803715808508367552534888528805294349032974654510188342040360434546186772033364970122751107815637177999884023419465307981287775545624662147033431554548397122324267017234070663720400746712194770054252442468101048673992585806405213093888136210578305171074909168912470580622477998700793884847359207107059238639060788976078179080818314767030461322323395047113995358033993569408291939269922853683527050945185700788760652012934482300494088778703962457717411473395412883903804762976980033721630846529810351956621569599613380405653666162124279393550337
Yields the output
680
107119977774651371253452527383378795643813350566102489275129938077182413874332698326138591399011209263442488431346187845236538851430516250893669985358034245316895848851593906428586406317712138354510870480814622758587775801557863785321825161899042872084983788917762574083608699791244667034031670755772364943146