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

In summary, the conversation is about creating a script to generate random keys using Python. The code is not very refined, but it works. The language used is Python and the solution involves saving the file and using the command "python filename > output_filename" to imitate a typing stream. The finished script includes code for generating random keys using a combination of letters, numbers, and special characters, as well as words from a dictionary.
  • #1
Alexi-dono
13
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:
Technology news on Phys.org
  • #2
I figured it out...
 
  • #3
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:
 
  • #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)
 

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

1. How can I install Python on my operating system?

To install Python on your operating system, you can go to the official Python website and download the installer for your specific OS. Once the installer is downloaded, simply follow the installation instructions to complete the process.

2. How can I check if Python is already installed on my operating system?

To check if Python is already installed on your operating system, you can open a terminal or command prompt and type in python --version. If Python is installed, it will display the version number. If not, you will receive an error message.

3. How can I add Python to my OS's path?

To add Python to your OS's path, you can go to the environment variables settings and add the path to your Python installation directory to the PATH variable. This will allow you to run Python commands from any directory in your terminal or command prompt.

4. How can I run a Python script from my OS's terminal or command prompt?

To run a Python script from your OS's terminal or command prompt, you can navigate to the directory where the script is located and type in python script_name.py. This will execute the script and display any output or errors in the terminal or command prompt.

5. How can I use Python to generate entropy on my operating system?

To use Python to generate entropy on your operating system, you can use the os.urandom() function. This function returns a string of random bytes that can be used as a source of entropy for cryptographic operations or other purposes.

Similar threads

  • Programming and Computer Science
Replies
6
Views
5K
Replies
1
Views
2K
  • Programming and Computer Science
Replies
5
Views
2K
Back
Top