SHARE
TWEET

randomCharacters.py




Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- # randomCharacters.py
- # Program that generates random PLAINTEXT combinations of characters
- import random
- import string
- import os
- def main():
- print("\nCreates random combinations of characters based on user input.\n")
- # Get user input (amounts, symbols yes/no, min length, max length)
- combination_amount = int(input("How many combinations should be generated? "))
- c_symbol = str(input("Can punctuation and special characters be used (Y/N)? "))
- if c_symbol == "y" or c_symbol == "Y":
- c_symbol = string.punctuation
- else:
- c_symbol = ""
- c_min_char = int(input("Minimum number of characters? "))
- c_max_char = int(input("Maximum number of characters? "))
- if c_max_char < c_min_char:
- c_min_char, c_max_char = c_max_char, c_min_char
- # Create a file for the PLAINTEXT combinations and write to it
- filename = "random_combinations"
- while os.path.isfile(filename + ".txt") == True: # Adds _new to the name if file exists
- filename += "_new"
- filename += ".txt"
- f = open(filename, "w")
- # Generate combinations using the random and string modules, and writes it as PLAINTEXT to the file
- for i in range (combination_amount):
- combination_mixer = "".join(random.choices(string.ascii_uppercase + string.ascii_lowercase + string.digits + c_symbol, k=random.randint(c_min_char, c_max_char)))
- f.write(combination_mixer + "\n")
- # Save the file and open it for the user
- print("Generated", combination_amount, "combinations.\nSaved as:", os.getcwd() + "\\" + filename)
- f.close()
- os.startfile(os.getcwd() + "\\" + filename)
- run_again = str(input("Run again (Y/N)? "))
- if run_again == "Y" or run_again == "y":
- main()
- if __name__ == "__main__":
- main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.