I'm trying to implement a basic procedure to generate an RSA key. The procedure accepts a range of numbers a and b. It has to check that the intervall between a and b is "five digits".
So I came up with a solution:
with (numtheory);
gen_rsa := proc(a, b)
local p, q, len_p, len_q, larger;
# the two prime-numbers
p:=safeprime(round(RandomTools[Generate](integer(range=a .. b))-1/2));
q:=safeprime(round(RandomTools[Generate](integer(rande=a .. b))-1/2));
if( evalb(log10(p) > log10(q)+5 )
[...]
Thing is: Maple seems to understand p and q as variables of the type function. I want to use the log10 to find out how many digits the prime-number has in order to calculate a safe RSA key. So evalb
fails, because it cannot determine the two logarithms??
You shouldn't load the package outside the proc definition -- it's not good practice.
You don't need a call to evalb
, when using if...then
, as it automatically does that.
You could either use is
instead, or evalf both quantities so that the inequality can be tested.
For example,
gen_rsa := proc(a, b)
local p, q, len_p, len_q, larger;
uses numtheory, RandomTools;
randomize();
# the two prime-numbers
p:=safeprime(round(Generate(integer(range=a .. b))-1/2));
q:=safeprime(round(Generate(integer(range=a .. b))-1/2));
if is(log10(p) > log10(q)+5) then
hi;
else
bye;
end if;
end proc:
or you could replace that is
call by applying evalf
to both sides of the <
inequality conditional. (The is
command can actually utilize evalf
internally, possibly via shake
, to figure it out.)
What you mean by the "interval" between p and q being "5 digits" is not clear. If you mean that one must have five more decimal digits that the other then you might want to round or trunc those log10 calls separately. It's hard to say, as the wording is fuzzy.
ps. I also corrected the misspelling "rande" for "range", and removed the inappropriate open-parenthesis right after the if
. And the randomize
call will make the RandomTools command produce different answers after each restart or in each fresh session.