Group Abstract Group Abstract

Message Boards Message Boards

Fix code that does RSA decryption?

Posted 9 years ago
POSTED BY: Jens Burkhart
3 Replies

Your problem is that the v=Length[e] is in the While loop -- it needs to be outside -- the loop never runs a second time the way you have it. Do this (this is after 3 iterations with phi = 61):

v = Length[e];
While[Length[e] <= v,
 If[CoprimeQ[phi, z], {y, {a, b}} = ExtendedGCD[phi, z];
  If[b > 0, e = Append[e, {z, b}]]];
 z++; Print["z = ", z, "; v=", v, "; e = ", e]]

z = 10; v=2; e = {{1,1},{8,23}}

z = 11; v=2; e = {{1,1},{8,23}}

z = 12; v=2; e = {{1,1},{8,23}}

z = 13; v=2; e = {{1,1},{8,23}}

z = 14; v=2; e = {{1,1},{8,23}}

z = 15; v=2; e = {{1,1},{8,23}}

z = 16; v=2; e = {{1,1},{8,23}}

z = 17; v=2; e = {{1,1},{8,23}}

z = 18; v=2; e = {{1,1},{8,23},{17,18}}
POSTED BY: Neil Singer
Posted 9 years ago

Yeah basically I want this function to iterate and stop if an element got added to the list. This works the first time but does not after that. v gets set to 0 for some reason.

POSTED BY: Jens Burkhart

as soon as e gets assigned its first value, the iteration stops (Length[e]=1, v=0, Length[e] is not <=v, so e will have one element and v will be zero.

This seems to work as programmed, I am not sure I understand what you want to happen (so I can suggest a fix). Do you want the list to be rest to {}? If so, its not in the loop so it will not be.

Try this -- it does the same thing:

e = {}; z = 0; v = 0;
While[Length[e] <= v, v = Length[e];
 If[z == 5, e = {{1, 2}}];
 z++; Print["z = ", z, "; v=", v, "; e = ", e]]

z = 1; v=0; e = {}

z = 2; v=0; e = {}

z = 3; v=0; e = {}

z = 4; v=0; e = {}

z = 5; v=0; e = {}

z = 6; v=0; e = {{1,2}}
POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard