March 5th, 2004, 05:58 AM

RSA Encyrption and Decryption
Hello all!
I have literally only just started using python. I am trying to get my head around it all! What I want to do is to use the RSA algorithm> any pointers?
Cheers all this is VERY much appreciated.
Last edited by WWWebdesign; March 20th, 2004 at 12:35 PM.
March 5th, 2004, 10:08 AM

This is my try at the above but its bringing up syntax errors:
Old code removed as sooooo very very wrong
Last edited by WWWebdesign; March 20th, 2004 at 07:24 AM.
March 5th, 2004, 10:51 AM

Your code should look like this:
Code:
import primes
p=787;
q=1453;
n=p*q;
phin=(p1)*(q1);
e=12345876;
d=54367987;
i=len(string1)1;
x=0;
while (i != 1):
e=e2;
x=primes.gcd(n,e);
d=primes.invmod(phin,e);
i=0;
x=n;
while (x !=0):
x=x>>8;
i=i*1;
print i1
You forgot the colons [:] at the end of your while statement. Also, you weren't indenting. You might have been, but I couldn't tell.
Also, is primes a thirdparty module or something, or maybe even a module you made? I don't have this module with my Python.
Anyways, tell us how it goes.
March 5th, 2004, 11:17 AM

Well now how do you use it... I am not sure on how to use this sort of program. Because I know how to run it but how to get it to run on the password or whatever to crak/decrypt.
March 5th, 2004, 12:10 PM

oh primes is from
I am working my way through it. Is there any chance you can run me through whats happening above please!
Last edited by WWWebdesign; March 20th, 2004 at 07:25 AM.
March 5th, 2004, 12:44 PM

primes module
You are loading and running the module prime's code.
You are assigning variables. You are saying that p is 787 and q is 1453.
Code:
n=p*q;
phin=(p1)*(q1);
You are assigning variables. You are saying that n is the variable p (787) times the variable q (1453). You are saying that phin is the variable p (787) minus 1, times the variable q (1453) minus 1. (The math in the parentheses is done first)
Code:
e=12345876;
d=54367987;
You are assigning variables. You are saying that e is 12345876 and d is 54367987.
Code:
i=len(string1)1;
x=0;
while (i != 1):
e=e2;
x=primes.gcd(n,e);
d=primes.invmod(phin,e);
i=0;
x=n;
You are saying that i is the length of string minus 1, minus 1. (The math in the parentheses is done first.) You are saying that x is 0. First, you are saying "while i is not equal to 1". Then you're saying e is e minus 2. x is using the gcd definition in the primes module, and you are using n and e as the variables. d is using the invmod definition in the primes module, and you are using the variables phin and e. i is 0, and x is n.
Code:
while (x !=0):
x=x>>8;
i=i*1;
You are saying "while x is not equal to zero". Then you are saying that x is x shift right 8 bits. The >> (shift right) deals with binary stuff.
Say x is equal to 1. (0001)
Then you say: x << 2
This will shift the numbers two slots to the left to create a binary of four. Your outcome is: 0100
You are printing the variable i, minus 1.
While loops keep running until the statement is false. Lets say x is equal to 1, and your while statement says: while (x != 1):. Your while loop won't run, because it is false.
Does this help you out a bit? I'll try to explain whatever, a bit more, if you need me too.
You need to define string. (Line 11 in your code)
Last edited by MasterChief; March 5th, 2004 at 12:49 PM.
March 5th, 2004, 01:30 PM

excellent thats really useful! thanks!
Ok when I run the code I seem to be getting an error, to do with the prime module I think:
Traceback (most recent call last):
File "C:\Documents and Settings\JBloggs\Desktop\Networks\Python Work\Assign2.py", line 1, in ?
import primes
ImportError: No module named primes
March 5th, 2004, 01:42 PM

Where is your module currently located?
You should move it to:
C:\Python23\
or where ever you installed Python. (Put it in the main Python directory)
Tell us if you still get the error.
March 6th, 2004, 08:56 AM

Yeah that fixed it I think but now getting another message:
>>>
Traceback (most recent call last):
File "C:\Python22\Assign2.py", line 11, in ?
i=len(string1)1;
NameError: name 'string' is not defined
March 6th, 2004, 09:59 AM

I told you that you needed to define string.
What is string supposed to be? I'll try to help you define it.