myconfigfiles/.scripts/passwordGenerator.py

37 lines
729 B
Python
Raw Permalink Normal View History

2019-11-18 07:31:22 +01:00
#! /usr/bin/env python
import string
import random
from random import sample
def randChar(nb):
specialChar = ",?!'=()%*+/_.-[]#@{}"
charList = specialChar+string.digits+string.ascii_letters
s = sample(charList, nb)
for i in range(nb):
if random.random() < 0.2:
s[i] = s[i]+sample(charList, 1)[0]
return s
def randTab(x,y):
tab = []
for i in range(y):
tab.insert(len(tab), [])
tab[i] = randChar(x)
return tab;
def printtab(tab):
f = open('test.out', 'w')
for i in range(len(tab[0])):
f.write('\t'+str(i))
for i in range(len(tab)):
f.write('\n'+string.ascii_uppercase[i*2:(i+1)*2])
for j in range(len(tab[i])):
f.write('\t'+tab[i][j])
f.write('\n')
f.close()
tab = randTab(10,13)
printtab(tab)