Frage

Ich versuche, ein grundlegendes Verfahren zu implementieren einen RSA-Schlüssel zu generieren. Die Prozedur akzeptiert eine Reihe von Zahlen a und b. Es ist zu prüfen, ob das Intervall zwischen a und b „fünfstellig“.

So kam ich mit einer Lösung:

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 ) 
  [...]

Die Sache ist die: Maple scheint p und q als Variablen vom Typ Funktion zu verstehen. Ich mag die log10 verwenden, um herauszufinden, wie viele Stellen die Prime-Nummer hat, um einen sicheren RSA-Schlüssel zu berechnen. So evalb versagt, weil sie die beiden Logarithmen nicht bestimmen kann ??

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top