Title: QUEST3.MWS

> # quest3.mws
> `crypt/alphabet` := `abcdefghijklmnopqrstuvwxyz`
||`ABCDEFGHIJKLMNOPQRSTUVWXYZ`
||```1234567890-=~!@#$£%^&*()_+`
||` ,./<>?;':"[]{}|    `:
> 
> to_number := proc(st, string) 
local ll, nn, ss, ii;  
ll := length(st);
if ll = 0 then RETURN(0) fi; 
nn := 1;
for ii to ll do 
ss := SearchText(substring(st, ii .. ii),`crypt/alphabet`);
nn := 100*nn + ss 
od;
nn - 10^(2*ll) 
end:
> 
> from_number := proc(nn, integer) 
local ss, mm, ll, pp, ii, ans; mm := nn;
ll := floor(1/2*trunc(evalf(log10(mm))))+1;
ans := ``; for ii to ll do mm := mm/100;
pp := 100*frac(mm);
ss := substring(`crypt/alphabet`, pp..pp);
ans := cat(ss, ans); mm := trunc(mm)
od; ans end:
(a)
Making up RSA keys for A:
> pA:=nextprime(7868768576548654785448765785676576578);

> length(pA);

> qA:=nextprime(98698797898798798798797987987987);

> length(qA);

> nA:=pA*qA;

> length(nA);

> eA:=nextprime(56778);

> length(eA);

> phi_nA:=(pA-1)*(qA-1);

> igcdex(eA,phi_nA,'x','y');

> dA:= x mod phi_nA;

Making up RSA keys fo B:

> pB:=nextprime(765786587657654675467546754675786897689768768768);

> length(pB);

> qB:=nextprime(98798798798798797987768765876868768767657546);

> length(qB);

> nB:=pB*qB;

> length(nB);

> eB:=nextprime(5676);

> length(eB);

> phi_nB:=(pB-1)*(qB-1);
> 

> igcdex(eB,phi_nB,'x','y');

> dB:= x mod phi_nB;

(b)
> length(nA);

> length(nB);

As A's public modulus is less than B's A goes first.
> Message:=to_number(`The deal is off. A.`);

> length(Message);

> encrypt1:=Message&^dA mod nA;

> send1:=encrypt1&^eB mod nB;

A would send 'send1' to B:
B receives 'send 1' and reads A's message by doing the following
(c)
> receive1:=send1&^dB mod nB;

> decrypt1:=receive1&^eA mod nA;

> original1:=from_number(decrypt1);

(d)
> length(nA);

> length(nB);

B would do the following to sign the following message to A.
A's public modulus is less than B's therefore A goes first.
> message2:=to_number(`I don't care.B.`);

> length(message2);

> encrypt2:=message2&^eA mod nA;

> send2:=encrypt2&^dB mod nB;

A would do the following to read B's message.
> receive2:=send2&^eB mod nB;

> decrypt2:=receive2&^dA mod nA; 

> original2:=from_number(decrypt2);

>