Created
July 29, 2014 17:47
-
-
Save typosone/284079cb898b0ee07148 to your computer and use it in GitHub Desktop.
Python3 でランダム文字列作るやつ。
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 | |
import sys | |
import random | |
argv = sys.argv | |
argc = len(argv) | |
if argc not in {2, 3}: | |
print("Usage: pass_gen digis [mode(1:number,2:lower,4:upper,8:specials]") | |
quit() | |
if argc == 3: | |
mode = int(argv[2]) | |
else: | |
mode = 1 | |
length = int(argv[1]) | |
seed = "" | |
if mode & 0x01 == 1: | |
seed += "0123456789" | |
if mode >> 1 & 0x01 == 1: | |
seed += "abcdefghijklmnopqrstuvwxyz" | |
if mode >> 2 & 0x01 == 1: | |
seed += "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
if mode >> 3 & 0x01 == 1: | |
seed += "!@#$%^&*()_[];:,./<>" | |
print("".join([random.choice(seed) for x in range(length)])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment