Skip to content

Commit 73b6ec8

Browse files
committed
Arts Fern
1 parent 7d3582c commit 73b6ec8

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

README

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
qwgen
2+
=====
3+
4+
Generates random password using the Hadamard Gates in qiskit.
5+
6+
Works with Python3. Requires pyperclip and qiskit. Install them with pip.
7+
8+
Warning: It uses the qasm **simulator**. It's not implementing real quantum randomness but mimicking them with qiskit's simulator. So don't use it for serious work.
9+
10+
Usage:
11+
-c, --clipboard copies generated password into the clipboard
12+
-l <num>, --length <num> password length

qwgen.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python3
2+
3+
# Dependency: qiskit, pyperclip
4+
5+
def warn (* args, **kwargs):
6+
pass
7+
import warnings
8+
warnings.warn = warn
9+
10+
import argparse
11+
parser = argparse.ArgumentParser()
12+
parser.add_argument("-c", "--clipboard", action="store_true",
13+
help="paste to the clipboard")
14+
parser.add_argument("-l", "--length", type=int,
15+
help="password length")
16+
args = parser.parse_args()
17+
18+
import string, math
19+
from qiskit import *
20+
21+
import pyperclip
22+
23+
24+
table = string.ascii_uppercase + string.ascii_lowercase + string.digits
25+
circ = QuantumCircuit(6)
26+
27+
for q in range(6):
28+
circ.h(q)
29+
30+
circ.measure_all()
31+
32+
backend_sim = Aer.get_backend('qasm_simulator')
33+
34+
def rand_int():
35+
rand = 62
36+
while rand > 61:
37+
job_sim = execute(circ, backend_sim, shots=1)
38+
result_sim = job_sim.result()
39+
40+
count = result_sim.get_counts(circ)
41+
bits = max(count, key=lambda i: count[i])[:6]
42+
rand = int(bits, 2)
43+
return rand
44+
45+
pwlen = 8
46+
if args.length:
47+
pwlen = args.length
48+
49+
if args.clipboard:
50+
pyperclip.copy(''.join(table[rand_int()] for _ in range(pwlen)))
51+
print("Random password copied to clipboard")
52+
else:
53+
for i in range(20):
54+
for j in range(8):
55+
pw = ''.join(table[rand_int()] for _ in range(pwlen))
56+
print(pw+' ', end='')
57+
print('\n', end='')

0 commit comments

Comments
 (0)