Skip to content

Instantly share code, notes, and snippets.

Last active Jan 8, 2017
What would you like to do?
A script to generate a random numeric pin along with a string of possible ‘phone keyboard phrases’ (using the letters shown on a phone keyboard, setting 1 to punctuation and 0 to language-specific letters).
from random import choice
available_numbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
numbers_to_letters = {"1":["."],
"2":["A", "B", "C"],
"3":["D", "E", "F"],
"4":["G", "H", "I"],
"5":["J", "K", "L"],
"6":["M", "N", "O"],
"7":["P", "Q", "R", "S"],
"8":["T", "U", "V"],
"9":["W", "X", "Y", "Z"],
"0":["Æ", "Ø", "Å"]}
def generate_pin(length=4):
pin = ""
for i in range(length):
pin += choice(available_numbers)
return pin
def generate_mnemomic_phrase(numbers, prefix_string=""):
if not numbers:
for l in numbers_to_letters[numbers[0]]:
generate_mnemomic_phrase(numbers[1:], prefix_string + l)
if __name__ == "__main__":
a = generate_pin()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment