FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects

Generate UCAM COVID testing barcodes

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    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()
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment