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
# Use random.org
$ python dwg.py # by default, it will generate 6-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
$ python dwg.py # by default, it will generate 6-word password
$ python dwg.py 7 # generate 7-word password
```

52
dwg.py
View File

@ -1,63 +1,27 @@
import json
import random
import sys
import pandas as pd
import requests
DW = pd.read_csv('pinyin.wordlist')
SEPARATOR = [
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '"', '#', '$', '%',
'&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>',
'?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~'
'!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|',
'}', '~'
]
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 = []
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):
ID = int(''.join(str(d) for d in DATA[i * 5:i * 5 + 5]))
SELECT = DW[DW['id'] == ID]
CHT.append(SELECT['cht'].values[0])
WORD.append(SELECT['word'].values[0])
ID = random.SystemRandom().randint(0, 8191)
CHT.append(DW['cht'].values[ID])
WORD.append(DW['word'].values[ID])
PAYLOAD['params']['n'] = 1
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']
ID = random.SystemRandom().randint(0, 31)
print(' '.join(CHT))
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