1 ======================================================================
2 tesid: Python library for Textualised Encrypted Sequential Identifiers
3 ======================================================================
5 This package implements the TESID scheme for producing short, human-friendly,
6 cryptographically-secure pseudorandom strings out of sequential identifiers.
8 See https://chrismorgan.info/tesid/ for more information about TESID.
10 A simple demonstration:
14 from tesid import TESIDCoder
16 secret_key = '000102030405060708090a0b0c0d0e0f'
17 coder = TESIDCoder(secret_key)
19 assert coder.encode(0) == 'w2ej'
20 assert coder.encode(1) == 'w6um'
21 assert coder.encode(2) == 'x45g'
22 assert coder.encode(2**20 - 1) == 'atcw'
23 assert coder.encode(2**20) == '8qwm6y'
24 assert coder.encode(2**30 - 1) == '3eipc7'
25 assert coder.encode(2**30) == 'n3md95r4'
26 assert coder.encode(2**100 - 1) == 'ia2bvpjaiju7g5uaxn5t'
27 # coder.encode(2**100) would raise ValueError.
28 assert coder.decode('w2ej') == 0
30 # And with the most convenient form of type discrimination:
31 # (You can also do all this through TESIDCoder, but it’s less convenient.)
32 from tesid import TypedTESIDCoder, SplitDecode
40 typed_coder = TypedTESIDCoder(coder, 256, Type)
42 assert typed_coder.encode(Type.A, 0) == 'w2ej'
43 assert typed_coder.encode(Type.B, 0) == 'w6um'
44 assert typed_coder.encode(Type.C, 0) == 'x45g'
45 assert typed_coder.encode(Type.A, 1) == 'dh2h'
46 assert typed_coder.encode(Type.B, 1) == 'a6xy'
47 assert typed_coder.encode(Type.C, 1) == '7xgj'
48 assert typed_coder.decode(Type.A, 'w2ej') == 0
49 # typed_coder.decode(Type.B, 'w2ej') will raise ValueError.
50 assert typed_coder.split_decode('w2ej') == \
51 SplitDecode(id=0, discriminant=Type.A)
56 **Authorship:** `Chris Morgan <https://chrismorgan.info/>`_ is the author and
57 maintainer of this library.
59 **Licensing:** this library is distributed under the terms of the
60 `Blue Oak Model License 1.0.0 <https://blueoakcouncil.org/license/1.0.0>`_ and
61 the `MIT License <https://opensource.org/licenses/MIT>`_, at your choice.
62 See COPYRIGHT_ for details.