Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 5th, 2004, 05:58 AM
WWWebdesign WWWebdesign is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 10 WWWebdesign User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old March 5th, 2004, 10:08 AM
WWWebdesign WWWebdesign is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 10 WWWebdesign User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #3  
Old March 5th, 2004, 10:51 AM
MasterChief MasterChief is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 543 MasterChief User rank is Sergeant (500 - 2000 Reputation Level)MasterChief User rank is Sergeant (500 - 2000 Reputation Level)MasterChief User rank is Sergeant (500 - 2000 Reputation Level)MasterChief User rank is Sergeant (500 - 2000 Reputation Level)MasterChief User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 11 h 18 m 34 sec
Reputation Power: 23
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.

Reply With Quote
  #4  
Old March 5th, 2004, 11:17 AM
reaper69 reaper69 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 30 reaper69 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
Arrow

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.

Reply With Quote
  #5  
Old March 5th, 2004, 12:10 PM
WWWebdesign WWWebdesign is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 10 WWWebdesign User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #6  
Old March 5th, 2004, 12:44 PM
MasterChief MasterChief is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 543 MasterChief User rank is Sergeant (500 - 2000 Reputation Level)MasterChief User rank is Sergeant (500 - 2000 Reputation Level)MasterChief User rank is Sergeant (500 - 2000 Reputation Level)MasterChief User rank is Sergeant (500 - 2000 Reputation Level)MasterChief User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 11 h 18 m 34 sec
Reputation Power: 23
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.

Reply With Quote
  #7  
Old March 5th, 2004, 01:30 PM
WWWebdesign WWWebdesign is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 10 WWWebdesign User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #8  
Old March 5th, 2004, 01:42 PM
MasterChief MasterChief is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 543 MasterChief User rank is Sergeant (500 - 2000 Reputation Level)MasterChief User rank is Sergeant (500 - 2000 Reputation Level)MasterChief User rank is Sergeant (500 - 2000 Reputation Level)MasterChief User rank is Sergeant (500 - 2000 Reputation Level)MasterChief User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 11 h 18 m 34 sec
Reputation Power: 23
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.

Reply With Quote
  #9  
Old March 6th, 2004, 08:56 AM
WWWebdesign WWWebdesign is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 10 WWWebdesign User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #10  
Old March 6th, 2004, 09:59 AM
MasterChief MasterChief is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 543 MasterChief User rank is Sergeant (500 - 2000 Reputation Level)MasterChief User rank is Sergeant (500 - 2000 Reputation Level)MasterChief User rank is Sergeant (500 - 2000 Reputation Level)MasterChief User rank is Sergeant (500 - 2000 Reputation Level)MasterChief User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 11 h 18 m 34 sec
Reputation Power: 23
I told you that you needed to define string.

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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > RSA Encyrption and Decryption

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap