|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
Your code should look like this:
Code:
import primes
p=787;
q=1453;
n=p*q;
phin=(p-1)*(q-1);
e=12345876;
d=54367987;
i=len(string-1)-1;
x=0;
while (i != 1):
e=e-2;
x=primes.gcd(n,e);
d=primes.invmod(phin,e);
i=0;
x=n;
while (x !=0):
x=x>>8;
i=i*1;
print i-1
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 third-party 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. |
|
#4
|
|||
|
|||
|
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.
|
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
primes module
Code:
import primes You are loading and running the module prime's code. Code:
p=787; q=1453; You are assigning variables. You are saying that p is 787 and q is 1453. Code:
n=p*q; phin=(p-1)*(q-1); 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(string-1)-1;
x=0;
while (i != 1):
e=e-2;
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 Code:
print i-1 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. |
|
#7
|
|||
|
|||
|
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 |
|
#8
|
|||
|
|||
|
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. |
|
#9
|
|||
|
|||
|
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(string-1)-1; NameError: name 'string' is not defined |
|
#10
|
|||
|
|||
|
I told you that you needed to define string.
What is string supposed to be? I'll try to help you define it. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > RSA Encyrption and Decryption |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|