Group Abstract Group Abstract

Message Boards Message Boards

Fix code that does RSA decryption?

Posted 9 years ago

A few days ago I started working on a method to decrypt a text with a given number phi(N). For that, I need to create a list of possible (e,d). I can calculate e and d (in this example d=b and z=e, e is the list with (e,d)) with

If[CoprimeQ[phi, z],
{y, {a, b}} = ExtendedGCD[phi, z]; 
If[b > 0, e = Append[e, {z, b}]]
]

where phi and e have to be coprime and 1 < e < phi. Now instead of iterating this in the first place over all possible z (which don't have to be prime but uneven), I want to create a small number of (e,d). This number can vary and depends on phi. Now if I test a few z, not all of the z will give me another (e,d) because not all z are coprime to phi and not all b are positive.

But in order to guarantee that i always get just one more (e,d) i wrote a little code, which doesn't seem to work and I just don't know why.

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

v is the old length of the list e and should be compared to the new length. If the new length is smaller or equal to v, the algorithm should start over again until the new length is bigger than v, the old length.

Now for some reason v is always equal to 0. But Length[e] is not! Can someone tell me what happens here?

POSTED BY: Jens Burkhart
3 Replies
POSTED BY: Neil Singer
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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard