-
Notifications
You must be signed in to change notification settings - Fork 1
/
EtLaUnMecTeDit__NIST
executable file
·55 lines (41 loc) · 1.74 KB
/
EtLaUnMecTeDit__NIST
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /usr/bin/env python3
# -*- coding: utf-8; mode: python -*-
""" Tiny Python 2/3 script to output a random number, like if your friend was telling it:
$ EtLaUnMecTeDit__NIST
Hmmm, 1DC97AAEA5B7D694C0376111702D34A15279066D15E45A8FDC3292835FEA4AA20D7E5EB097700380CE700EC625D60043E9F1D9319AB778EA4D464B68F7D7AD4E
$ EtLaUnMecTeDit__NIST
Hmmm, 14F1EB1615F65CD2AB0A7F0302250DE55D8F42F835A6A0B9A2B0F4292745826B27389A64771434CC94F769D73592AE08AAD09C382E0F10D931CE2A9D28DA2125
You can reduce the number of digits:
$ EtLaUnMecTeDit__NIST 10
Hmmm, 14F1EB1615
$ EtLaUnMecTeDit__NIST 12
Hmmm, 14F1EB1615F6
It uses the NIST beacon (https://beacon.nist.gov/home) to output "true" random generator.
- *Date:* 14/06/2017
- *Author:* Lilian Besson, © 2017.
- *Licence:* MIT Licence (http://lbesson.mit-license.org).
"""
from __future__ import print_function # Python 2 compatibility if needed
from sys import argv
try:
from urllib.request import urlretrieve
except ImportError:
from urllib import urlretrieve
from tempfile import NamedTemporaryFile
import xml.etree.ElementTree as ET
URL = "https://beacon.nist.gov/rest/record/last"
def randint_from_beacon(maxlen=None, beacon_url=URL):
"""Read 'https://beacon.nist.gov/rest/record/last' and output a random number."""
with NamedTemporaryFile() as this_temp_file:
path_of_f = this_temp_file.name
urlretrieve(beacon_url, path_of_f)
tree = ET.parse(path_of_f)
root = tree.getroot()
tag = root.tag
result = root.find(tag.replace('}record', '}outputValue')).text
if maxlen is not None:
result = result[:maxlen]
return result
if __name__ == '__main__':
maxlen = int(argv[1]) if len(argv) > 1 else None
print("Hmmm,", randint_from_beacon(maxlen))