[PATCH] change semantics of "delete" LFUNs again (was: Re: Assertion from command-sequence)

José Matos jaomatos at gmail.com
Sun Dec 4 21:13:08 UTC 2022


On Sun, 2022-12-04 at 21:12 +0100, Jean-Marc Lasgouttes wrote:
> I finally managed to convinced python to like me, and pushed the
> result.
> 
> JMarc

Nice, I intended to look into this issue this weekend.

On the other hand I was concerned with encoding a text message in
integer number that in Python is infinite precision:

def encode(message):
    val = 0
    for c in message:
        val = val*64 + ord(c.replace(' ', '_')) - ord('A')
    return val

I am replacing the space (code 32) with the underscore (code 95) for
obvious reasons.

In [2]: encode("Hello fellow LyX developers")
Out[2]: 691762051676284770344776816411513612200769899634

def decode(data):
    message = []
    while data:
        c = data % 64
        message.append(chr(c+ord('A')))
        data //= 64
    return "".join(message[::-1]).replace('_', ' ')

In [4]: decode(encode("Hello fellow LyX developers"))
Out[4]: 'Hello fellow LyX developers'

This allows to encode and decode a message into a number.

Best regards,
-- 
José Abílio


More information about the lyx-devel mailing list