Jun-03-2024, 09:43 PM
(This post was last modified: Jun-03-2024, 09:43 PM by Gribouillis.)
I can only answer the first question, yes I think Python is an excellent choice for this task.
Here is my attempt to code the
Here is my attempt to code the
pack()
function. Tell me if the result looks correctr50 = b'ABCDEFGHIJKLMNOPQRSTUVWXYZ.$%0123456789' illegal = 127 def prepare_table(): s = r50.decode('ascii') d = {ord(c): i for i, c in enumerate(s)} d.update({ord(c.lower()): i for i, c in enumerate(s)}) L = [illegal for i in range(256)] for c, i in d.items(): L[c] = i table = ''.join(chr(x) for x in L).encode('ascii') return table table = prepare_table() class IllegalCharacter(Exception): pass def pack(c3): x = c3.translate(table) if illegal in x: raise IllegalCharacter return 1600 * x[0] + 40 * x[1] + x[2] res = pack(b'tom') print(res)
Output:λ python paillasse/pf/curbie.py
30972
« We can solve any problem by introducing an extra level of indirection »