#!/bin/env python # # Freeman Lo # # http://www.random.org/decimal-fractions/?num=100&dec=20&col=1&format=html&rnd=new # http://www.random.org/decimal-fractions/?num=key1&dec=key28&col=1&format=html&rnd=new # # An improved version of locating a random password. # Pulling a random number from random.org by parsing its webpage. # ################################################################################### def askForInputs(): #k1 = raw_input("Please enter a value less than 10000 ? ") #k2 = raw_input("Please enter an amount up to 20 ? ") #a,b = 0,0 #if k1.isdigit() and k2.isdigit: # a = int(k1) # b = int(k2) # setWebValues(a,b) setWebValues(200,19) #else: # print "Inputs are not digits, Please try again !" def setWebValues(key1, key2): import requests from BeautifulSoup import BeautifulSoup payload = {"num":key1, "dec":key2, "col":"1", "format":"html", "rnd":"new"} r = requests.get("http://www.random.org/decimal-fractions/", params=payload) page = BeautifulSoup(r.content) # Not sure r.close() will work in linux # strangely enough, it works in windose r.close() setRandomNum(page, key2) def setRandomNum(wp, key2): import random import decimal from decimal import getcontext decimal.getcontext().prec = key2 c="" z = wp.find('pre') for a in z: c=c+a c = c.encode('ascii') d = c.split("\n") d.pop() #print d[10] #mn = float(d[random.randint(0,len(d)-1)]) mn = decimal.Decimal(d[random.randint(0,len(d)-1)]) #print mn findMagicPassword(mn) def findMagicPassword(magNum): import string import random # see Ma, no random.seed(time.time()) ! random.seed(magNum) mess = "" mess = string.digits mess = mess + string.ascii_uppercase mess = mess + string.ascii_lowercase # no punctuations are included in this passcode. letterList = [] for i in mess: letterList.append(i) word, pword = "", "" a,tmp = 0,0 while a < 10: # By changing the 10 to a 15, the password will become longer tmp = random.randint(0, len(letterList)-1) letter = str(letterList[tmp]) pword = pword + letter a=a+1 print "Password is: " + pword def main(): import sys askForInputs() sys.exit(0) main()