Last active
December 14, 2015 22:18
-
-
Save dgrant/5157156 to your computer and use it in GitHub Desktop.
Generates a mapping of all letters of the alphabet to a 2-character combination of uppercase, lowercase, or digits. A great way to come up with a random password for a website.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Generate a password map | |
""" | |
import itertools | |
import random | |
from string import ascii_lowercase, ascii_uppercase | |
def main(): | |
"""Main script""" | |
my_digits = "123456789" | |
trans = str.maketrans("", "", 'lO') | |
my_lowercase = ascii_lowercase.translate(trans) | |
my_uppercase = ascii_uppercase.translate(trans) | |
sets = (my_lowercase, my_digits, my_uppercase) | |
columns = 4 | |
counter = 0 | |
for letter in ascii_uppercase: | |
counter += 1 | |
combo = random.choice(list(itertools.permutations(range(3), 2))) | |
first_index, second_index = combo | |
first_set, second_set = sets[first_index], sets[second_index] | |
letter1 = random.choice(first_set) | |
letter2 = random.choice(second_set) | |
print(letter + " -", letter1 + letter2, end=' ') | |
if counter == columns: | |
print() | |
counter = 0 | |
print() | |
if __name__ == "__main__": | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Random (randomRIO) | |
pick :: [a] -> IO a | |
pick xs = randomRIO (0, (length xs - 1)) >>= return . (xs !!) | |
lowercase :: [Char] | |
lowercase = [x | x <- ['a'..'z'], x `notElem` "l"] | |
uppercase :: [Char] | |
uppercase = [x | x <- ['A'..'Z'], x `notElem` "O"] | |
numbers :: [Char] | |
numbers = ['1'..'9'] | |
allPairs :: [(Char, Char, Char)] | |
allPairs = [ (uppercase!!(i-1), numbers!!(j-1), lowercase!!(k-1)) | |
| i <- [1..(length uppercase)], | |
j <- [1..(length numbers)], | |
k <- [1..(length lowercase)]] | |
somePairs :: [IO (Char, Char, Char)] | |
somePairs = [ pick allPairs | _ <- [1..26] ] | |
main = do [n <- x | x <- someMPairs] | |
print n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment