Generate UCAM COVID testing barcodes
The snippet can be accessed without any authentication.
Authored by
Dr Rich Wareham
gen-codes.py 708 B
#!/usr/bin/env python3
import base64
import hashlib
import secrets
def gen_code():
"""
Generate a random barcode identifier corresponding to the current strawman
proposal.
https://docs.google.com/document/d/1td8uYbrubzXGzsYI95tqQU_O6rmwWsaBwAHH-JIDPOE/edit
"""
sample_id = secrets.token_bytes(8)
payload = base64.b32encode(sample_id).rstrip(b'=')
check_digest = hashlib.sha256()
check_digest.update(payload)
check_payload = base64.b32encode(check_digest.digest()[:3]).rstrip(b'=')
return f'UCAM-{payload.decode("ascii")}-{check_payload.decode("ascii")}'
def main():
for _ in range(10):
print(gen_code())
if __name__ == '__main__':
main()
Please register or sign in to comment