A PH private -key demonstration

Suppose 'Alice' wishes to send the message ' Hi Bob, let's meet ' to 'Bob' using P-H. This is what they do:

> p := nextprime(10^70 + rand()); # step 1

p := 1000000000000000000000000000000000000000000000...

> e := nextprime(10^15);

e := 1000000000000037

> igcd(e, p-1); # testing that '2' holds

1

> igcdex(e, p-1, 'x', 'y'):
d := x mod (p-1); # Step 3, finding 'd'

d := 9382748813408072838293903901304983125555651715...

>

Here - just to let you see - is ed :

> e*d;

938274881340842000000000000000000000000000000000000...

>

And see that ed does leave remainder 1 on division by ( p-1 ):

> e*d mod (p-1);

1

>

Next, Alice converts her message to a number:

> Anum := to_number(`Hi Bob, let's meet. Alice`);

Anum := 3409802815028180120520881980130505208280271...

> length(Anum);

50

>

Alice then encrypts that number (she lays on her coat of paint, as it were) by calculating the remainder (the least positive one) that Anum^e leaves on division by p . I'll call the resulting number Asend , since it's that number Alice sends to Bob. That is a remarkable calculation, as I would like to demonstrate. First see how Maple computes powers; I'll illustrate with 13^900 (which has 1003 digits; in my live presentation I'll vary that to 13^90000 - which has 100,255 digits - but won't leave that output when placing this worksheet on my web site):

> 13^900;

354011260283159548761403020847710190905720457568009...
354011260283159548761403020847710190905720457568009...
354011260283159548761403020847710190905720457568009...
354011260283159548761403020847710190905720457568009...
354011260283159548761403020847710190905720457568009...
354011260283159548761403020847710190905720457568009...
354011260283159548761403020847710190905720457568009...
354011260283159548761403020847710190905720457568009...
354011260283159548761403020847710190905720457568009...
354011260283159548761403020847710190905720457568009...
354011260283159548761403020847710190905720457568009...
354011260283159548761403020847710190905720457568009...

>

But see what happens if we try to compute A_num^e :

> Anum^e;

Error, integer too large in context

>

Hardly a surprise, since Anum^e has billions upon billions of digits, and Maple can only compute powers up to a couple of million digits. It is something of a minor miracle that one can quickly compute the remainder that Anum^e leaves on division by p , without computing Anum^e itself (the mathematics involved uses congruences , together with the so-called square-and-multiply method, invoked by the '&' in the following Maple command):

> Asend := Anum&^e mod p;

Asend := 608047871512661339768821786557377364214953...

>

In passing let us observe the text equivalent of that encrypted number; it is just meaningless junk (I may have to recompute with another 'p' should there be a '00' in that string in the wrong position):

> from_number(Asend);

`7 U;ol~mM('u_=4K^-uW\`I/NY)@J}s'_Jgq`

>

And this is what Bob does to read Alice's message: he decrypts (he strips off the disuising coat of paint, as it were) by calculating the remainder (again the least positive one) that Asend^d leaves on division by p. The connection between e , d , and ( p-1 ) in requirement #3, together with the mathematics of Fermat's little theorem (if p is any prime, and a is any integer not divisible by p , then a^(p-1) leaves remainder 1 on division by p ) - gaurantees that the outcome is the numerical form of the original text:

> Bsee := Asend&^d mod p;

Bsee := 3409802815028180120520881980130505208280271...

> from_number(Bsee);

`Hi Bob, let's meet. Alice`

>

Wonderful, yes?
(actually it's entirely elementary when you know the mathematics)

In responding to Alice, Bob may encrypt using either power (of course in practice Alice and Bob should agree in advance on this), meaning that he may encrypt using the decryption power, as I'll quickly demonstrate:

> Bnum := to_number(`Thanks Alice. Where? When? Bob`);

Bnum := 4608011411198027120903058280490805180586804...

> length(Bnum);

60

> Bsend := Bnum&^d mod p; #NOTE the 'd' power

Bsend := 322980065472853758693965025712179652761818...

>

Alice receives B_send, and then:

> Asee := Bsend&^e mod p; # NOTE the 'e' power

Asee := 4608011411198027120903058280490805180586804...

> from_number(Asee);

`Thanks Alice. Where? When? Bob`

>

Two final, quick points:

  • SECURITY. It should be obvious that both Alice and Bob must keep their 'keys' - ( e , p ) and ( d , p ) - secret: anyone who knows ( e , p ) may immediately compute d (using the extended Euclidean algorithm), or anyone who knows ( d , p ) may immediately compute e
  • SIZE OF TEXT. If the numerical form (Anum or Bnum) of either text is greater than p , then it must be broken down into numbers each having numerical value less than p (think about that to see why...)

Contact details 

After August 31st 2007 please use the following Gmail address: jbcosgrave at gmail.com


This page was last updated 18 February 2005 15:08:23 -0000