30 lines
1.3 KiB
Python
30 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
import base64, json
|
|
import qrcode
|
|
from qrcode.constants import ERROR_CORRECT_M
|
|
|
|
session = "qft_test_session_128bit_XY"
|
|
ssid = "QFT-DESKTOP-abc123"
|
|
password = "3xamplePassw0rd"
|
|
|
|
v2 = {"v":2,"s":session,"n":"DESKTOP-QFT","p":39393,"e":["http://192.168.137.1:39393"],"w":[ssid,password]}
|
|
raw2 = json.dumps(v2, separators=(",", ":"), ensure_ascii=False).encode()
|
|
text2 = "QFTPAIR2:" + base64.urlsafe_b64encode(raw2).decode().rstrip("=")
|
|
decoded = json.loads(base64.urlsafe_b64decode(text2.split(":",1)[1] + "=" * (-len(text2.split(":",1)[1]) % 4)))
|
|
assert decoded == v2
|
|
|
|
v1 = {
|
|
"v":1,"session":session,"pc_name":"DESKTOP-QFT","transport":"http-stream-v1","port":39393,
|
|
"endpoints":["http://192.168.137.1:39393","http://192.168.49.1:39393"],
|
|
"wifi":{"ssid":ssid,"passphrase":password,"security":"WPA2"},
|
|
}
|
|
raw1 = json.dumps(v1, separators=(",", ":")).encode()
|
|
text1 = "QFTPAIR1:" + base64.urlsafe_b64encode(raw1).decode().rstrip("=")
|
|
assert len(text2) < len(text1) * 0.60, (len(text2), len(text1))
|
|
|
|
qr = qrcode.QRCode(version=None, error_correction=ERROR_CORRECT_M, box_size=1, border=4)
|
|
qr.add_data(text2)
|
|
qr.make(fit=True)
|
|
assert qr.version <= 10, qr.version
|
|
print(f"PASS pairing: QFTPAIR2={len(text2)} chars vs v1={len(text1)} chars ({len(text2)/len(text1):.1%}), QR-M version={qr.version}")
|