Python Crypto.Random.random.choice() Examples
The following are 11
code examples of Crypto.Random.random.choice().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
Crypto.Random.random
, or try the search function
.
Example #1
Source File: password.py From CloudBot with GNU General Public License v3.0 | 6 votes |
def word_password(text, notice): """[length] - generates an easy to remember password with [length] (default 4) commonly used words""" try: length = int(text) except ValueError: length = 3 if length > 10: notice("Maximum length is 50 characters.") return words = [] # generate password for x in range(length): words.append(gen.choice(common_words)) notice("Your password is '{}'. Feel free to remove the spaces when using it.".format(" ".join(words)))
Example #2
Source File: strings.py From outis with MIT License | 5 votes |
def random_string(length=-1, charset=string.ascii_letters): """ Returns a random string of "length" characters. If no length is specified, resulting string is in between 6 and 15 characters. A character set can be specified, defaulting to just alpha letters. """ if length == -1: length = random.randrange(6, 16) rand_string = ''.join(random.choice(charset) for _ in range(length)) return rand_string
Example #3
Source File: strings.py From outis with MIT License | 5 votes |
def randomize_capitalization(data): """ Randomize the capitalization of a string. """ return "".join(random.choice([k.upper(), k]) for k in data)
Example #4
Source File: helpers.py From WSC2 with GNU General Public License v3.0 | 5 votes |
def randomString(length = -1, charset = string.ascii_letters): """ Author: HarmJ0y, borrowed from Empire Returns a random string of "length" characters. If no length is specified, resulting string is in between 6 and 15 characters. A character set can be specified, defaulting to just alpha letters. """ if length == -1: length = random.randrange(6,16) random_string = ''.join(random.choice(charset) for x in range(length)) return random_string #------------------------------------------------------------------------
Example #5
Source File: obfuscateCactusTorch.py From ObfuscateCactusTorch with GNU General Public License v3.0 | 5 votes |
def randomString(length = -1, charset = string.ascii_letters): """ Author: HarmJ0y, borrowed from Empire Returns a random string of "length" characters. If no length is specified, resulting string is in between 6 and 15 characters. A character set can be specified, defaulting to just alpha letters. """ if length == -1: length = random.randrange(6,16) random_string = ''.join(random.choice(charset) for x in range(length)) return random_string #------------------------------------------------------------------------
Example #6
Source File: helpers.py From WebDavC2 with GNU General Public License v3.0 | 5 votes |
def randomString(length = -1, charset = string.ascii_letters): """ Author: HarmJ0y, borrowed from Empire Returns a random string of "length" characters. If no length is specified, resulting string is in between 6 and 15 characters. A character set can be specified, defaulting to just alpha letters. """ if length == -1: length = random.randrange(6,16) random_string = ''.join(random.choice(charset) for x in range(length)) return random_string #------------------------------------------------------------------------
Example #7
Source File: Crypt.py From Crypter with GNU General Public License v3.0 | 5 votes |
def generate_key(self): # Function to generate a random key for encryption print("writing out key to " + os.getcwd()) key = ''.join(random.choice('0123456789ABCDEF') for i in range(32)) # DEV - Write to file fh = open("key.txt", "w") fh.write(key) fh.close() return key
Example #8
Source File: helpers.py From EmPyre with BSD 3-Clause "New" or "Revised" License | 5 votes |
def random_string(length=-1, charset=string.ascii_letters): """ Returns a random string of "length" characters. If no length is specified, resulting string is in between 6 and 15 characters. A character set can be specified, defaulting to just alpha letters. """ if length == -1: length = random.randrange(6, 16) random_string = ''.join(random.choice(charset) for x in range(length)) return random_string
Example #9
Source File: helpers.py From EmPyre with BSD 3-Clause "New" or "Revised" License | 5 votes |
def randomize_capitalization(data): """ Randomize the capitalization of a string. """ return "".join(random.choice([k.upper(), k]) for k in data)
Example #10
Source File: utils.py From python-hpedockerplugin with Apache License 2.0 | 5 votes |
def generate_password(length=16, symbolgroups=DEFAULT_PASSWORD_SYMBOLS): """Generate a random password from the supplied symbol groups. At least one symbol from each group will be included. Unpredictable results if length is less than the number of symbol groups. Believed to be reasonably secure (with a reasonable password length!) """ # NOTE(jerdfelt): Some password policies require at least one character # from each group of symbols, so start off with one random character # from each symbol group password = [random.choice(s) for s in symbolgroups] # If length < len(symbolgroups), the leading characters will only # be from the first length groups. Try our best to not be predictable # by shuffling and then truncating. random.shuffle(password) password = password[:length] length -= len(password) # then fill with random characters from all symbol groups symbols = ''.join(symbolgroups) password.extend([random.choice(symbols) for _i in range(length)]) # finally shuffle to ensure first x characters aren't from a # predictable group random.shuffle(password) return ''.join(password)
Example #11
Source File: password.py From CloudBot with GNU General Public License v3.0 | 4 votes |
def password(text, notice): """[length [types]] - generates a password of <length> (default 10). [types] can include 'alpha', 'no caps', 'numeric', 'symbols' or any combination: eg. 'numbers symbols'""" okay = [] # find the length needed for the password numb = text.split(" ") try: length = int(numb[0]) except ValueError: length = 12 if length > 50: notice("Maximum length is 50 characters.") return # add alpha characters if "alpha" in text or "letter" in text: okay += list(string.ascii_lowercase) # adds capital characters if not told not to if "no caps" not in text: okay += list(string.ascii_uppercase) # add numbers if "numeric" in text or "number" in text: okay += list(string.digits) # add symbols if "symbol" in text or "special" in text: sym = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '=', '_', '+', '[', ']', '{', '}', '\\', '|', ';', ':', "'", '.', '>', ',', '<', '/', '?', '`', '~', '"'] okay += sym # defaults to lowercase alpha + numbers password if the okay list is empty if not okay: okay = list(string.ascii_lowercase) + list(string.digits) # extra random lel random.shuffle(okay) chars = [] for i in range(length): chars.append(random.choice(okay)) notice("".join(chars))