Remove random.org version

This commit is contained in:
uohlhv 2021-10-02 15:40:52 +08:00
parent 7be9cee9cd
commit 852477aa6e
5 changed files with 8203 additions and 16047 deletions

View File

@ -13,10 +13,6 @@ $ poetry install
``` ```
$ poetry shell $ poetry shell
# Use random.org
$ python dwg.py # by default, it will generate 6-word password $ python dwg.py # by default, it will generate 6-word password
$ python dwg.py 7 # generate 7-word password $ python dwg.py 7 # generate 7-word password
# Use urandom
$ python dwg8k.py # by default, it will generate 6-word password
$ python dwg8k.py 7 # generate 7-word password
``` ```

52
dwg.py
View File

@ -1,63 +1,27 @@
import json import random
import sys import sys
import pandas as pd import pandas as pd
import requests
DW = pd.read_csv('pinyin.wordlist') DW = pd.read_csv('pinyin.wordlist')
SEPARATOR = [ SEPARATOR = [
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '"', '#', '$', '%', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|',
'?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~' '}', '~'
] ]
LENGTH = int(sys.argv[1]) if len(sys.argv) > 1 else 6 LENGTH = int(sys.argv[1]) if len(sys.argv) > 1 else 6
URL = "https://api.random.org/json-rpc/2/invoke"
PAYLOAD = {
"jsonrpc": "2.0",
"method": "generateIntegers",
"params": {
"apiKey": "1b426e57-4fdd-4c3e-92d5-eefcba185690",
"n": 5 * LENGTH,
"min": 1,
"max": 6,
"replacement": True,
"base": 10
},
"id": 10110
}
HEADERS = {'content-type': "application/json", 'cache-control': "no-cache"}
CHT = [] CHT = []
WORD = [] WORD = []
RESPONSE = requests.request("POST",
URL,
data=json.dumps(PAYLOAD),
headers=HEADERS)
DATA = json.loads(RESPONSE.text)['result']['random']['data']
for i in range(LENGTH): for i in range(LENGTH):
ID = int(''.join(str(d) for d in DATA[i * 5:i * 5 + 5])) ID = random.SystemRandom().randint(0, 8191)
SELECT = DW[DW['id'] == ID] CHT.append(DW['cht'].values[ID])
CHT.append(SELECT['cht'].values[0]) WORD.append(DW['word'].values[ID])
WORD.append(SELECT['word'].values[0])
PAYLOAD['params']['n'] = 1 ID = random.SystemRandom().randint(0, 31)
PAYLOAD['params']['min'] = 0
PAYLOAD['params']['max'] = 41
RESPONSE = requests.request("POST",
URL,
data=json.dumps(PAYLOAD),
headers=HEADERS)
DATA = json.loads(RESPONSE.text)
ID = DATA['result']['random']['data'][0]
REQUESTS_LEFT = DATA['result']['requestsLeft']
print(' '.join(CHT)) print(' '.join(CHT))
print(SEPARATOR[ID].join(WORD)) print(SEPARATOR[ID].join(WORD))
print('Request Left: ' + str(REQUESTS_LEFT))

View File

@ -1,27 +0,0 @@
import random
import sys
import pandas as pd
DW = pd.read_csv('pinyin8k.wordlist')
SEPARATOR = [
'!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|',
'}', '~'
]
LENGTH = int(sys.argv[1]) if len(sys.argv) > 1 else 6
CHT = []
WORD = []
for i in range(LENGTH):
ID = random.SystemRandom().randint(0, 8191)
CHT.append(DW['cht'].values[ID])
WORD.append(DW['word'].values[ID])
ID = random.SystemRandom().randint(0, 31)
print(' '.join(CHT))
print(SEPARATOR[ID].join(WORD))

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff