Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

[python] How can I get my OS to pick this up as entropy?

  1. Feb 25, 2015 #1
    So I am going to be making some keys; and I want to make them more random... So I made this:

    #I know that the code is pretty crude, but it works.
    #P.S. it is an infinite loop, run at your own risk
    import random
    from random import randint
    import string
    import time
    x=1
    n=randint(5,90)
    t=randint(20,1000)
    s=randint(404,700)
    char_set = string.ascii_uppercase + string.lowercase + string.digits + string.whitespace + string.punctuation
    words = [line.strip() for line in open('/etc/dictionaries-common/words')]
    while x>0:
    a=randint(1,2)
    r=a
    b=randint(1,2)
    k=b​
    if b>1:
    time.sleep(t/s)​
    if r>0:
    print ''.join(random.sample(char_set*s, n))
    time.sleep(t/s/t)​
    if r>1:
    print(random.choice(words))
    time.sleep(t/s/t)​
     
    Last edited: Feb 25, 2015
  2. jcsd
  3. Feb 25, 2015 #2
    I figured it out...
     
  4. Feb 25, 2015 #3

    jtbell

    User Avatar

    Staff: Mentor

    Just out of curiosity, which language was this in?

    And if you don't mind telling us what the solution was, maybe other people can benefit from it. :oldsmile:
     
  5. Feb 26, 2015 #4
    python, my semi-solution was to save the file and do this: "python filename > output_filename". i now need to find a way for it to imitate a typing stream; instead of a simple output. Any suggestions?

    finished script:
    import random
    from random import randint
    import string
    import time
    x=1
    n=randint(5,90)
    t=randint(200,5000)
    s=randint(404,700)
    char_set = string.ascii_uppercase + string.lowercase + string.digits + string.whitespace + string.punctuation
    words = [line.strip() for line in open('/etc/dictionaries-common/words')]
    while x>0:
    a=randint(1,2)
    r=a
    b=randint(1,2)
    k=b
    if b>1:
    time.sleep(t/1000)
    if r>0:
    print ''.join(random.sample(char_set*s, n))
    time.sleep(t/s/t)

    if r>1:
    print(random.choice(words))
    time.sleep(t/s/t)
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook