Welcome to Dream.In.Code
Become an Expert!

Join 149,614 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,869 people online right now. Registration is fast and FREE... Join Now!




Random Numbers and You

 
Reply to this topicStart new topic

Random Numbers and You, ...enjoying...

omoimasuyo
13 Sep, 2007 - 05:30 AM
Post #1

D.I.C Head
Group Icon

Joined: 19 Oct, 2006
Posts: 60


Dream Kudos: 50
My Contributions
I went looking for something with which I could use hexadecimal numbers and thought python would be something nice to play with.

At first, I thought it would be something complex like "toHexString" or something, but python smacked me in the face with its simplicity:

CODE
hex()


I could have died. Inspired by this piece of work, I went on to make something that could generate a few random passwords. I don't think it would work well for cryptography, but it's a start.

CODE
#!usr/bin/python

import random

def randomhex():
    base = int(random.randint(256,1024))
    exponent = int(random.randint(256,1024))
    lowerrange = int(random.randint(128,256))
    upperrange = int(random.randint(512,1024))
    hexval = hex(base**exponent)
    derivedpass = hexval[lowerrange:upperrange]
    print 'your hex number is: ' +hexval
    print 'your derived number is: ' +derivedpass

def genhex():
    answer = raw_input('Generate a number? (y/n)').lower()
    if (answer=='y'):
        randomhex()
        genhex()
    if (answer=='yes'):
        randomhex()
        genhex()
    else:
        print ('Thank you for trying the program!')

genhex()


Enjoy. If you can think of places to take this code, then take it there by all means. Share it with me, too, so I can keep learning. Rock on, guys.
User is offlineProfile CardPM
+Quote Post

rockstar_
RE: Random Numbers And You
18 Nov, 2007 - 09:41 PM
Post #2

D.I.C Head
Group Icon

Joined: 16 Oct, 2006
Posts: 187


Dream Kudos: 275
My Contributions
If you're looking for a cryptography library for python, there's lots of stuff hiding in the stdlibs. Try 'import des, md5, RSA' and play around with that.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 12:29AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month