Question: What's wrong with the code?

 A RSA with the modulus n = 119 and the exponent e = 7, with the 95-character
alphabet consisting of the printable ASCII characters to encrypt the word “Yes”.
so that Y=58, e=70, s=84. Give your encryption as a list of three numbers.

Then use the same set (that is the modulus n = 119 and the exponent e = 7) to decrypy the list of number  [42,59,4,59,27,59]

Here is my code, what's wrong with it. Please help. Thanks

RSASetUp:=proc(d::posint)
local pm,qm,p,q,n,phi,e,x;
pm:=floor((d-1)/2);
qm:=d-pm;
p:=nextprime(rand(10^(pm-1)..10^(pm))());
q:=nextprime(rand(10^(qm-1)..10^(qm))());
n:=p*q;
phi:=(p-1)*(q-1);
e:=rand(3..phi/2)();
while(gcd(e,phi)<>1) do e:=rand(3..phi/2)(); od;
x:=modp(1/e,phi);
return([n,e],[n,x]);
end proc:
ourKey:=RSASetUp(119);
with(StringTools):
Alphabet:=cat(op(select(IsPrintable,[seq(convert([i],bytes), i=1..255)]))):
ListToString:=proc(numlist::list(nonnegint))
global Alphabet;
cat(seq(Alphabet[numlist[i]+1],i=1..nops(numlist)));
end proc:
StringToList:= proc(text::string)
global Alphabet:
[seq(SearchText(text[i],Alphabet),i=1..length(text))];
end proc:
StringToKgraph:=proc(text::string,k::posint)
global Alphabet;
local numlist,len;
len:=length(Alphabet);
numlist:= StringToList(text);
convert(numlist, base, len, len^k);
end proc:
StringToKgraph("Yes",1);

KgraphToString:=proc(numlist::list(nonnegint), k::posint)
global Alphabet;
local len;
len:=length(Alphabet);
ListToString(convert(numlist,base, len^k, len));
end proc:
v:=[41,58,3,58,26,58];
KgraphToString(v,1);

 

 

Please Wait...