Re: [exim] Decode base 62 message ID

Startseite
Nachricht löschen
Nachricht beantworten
Autor: Björn Keil
Datum:  
To: exim-users
Betreff: Re: [exim] Decode base 62 message ID


Am Donnerstag, den 08.05.2008, 15:19 +0200 schrieb Karl Fischer:
> Björn Keil wrote:
> > Hello,
> >
> > I am trying to find a way to decode the base 62 encoding used for
> the
> > date in the message ID. I've written a little python program, but
> the
> > results don't seem quite right:
> >
> > I started out with the assumption that the numbers were given big
> endian
> > (as any human readable number) and that the values of digits were
> their
> > own, a -> z => 10 -> 35 and A -> Z => 36 -> 61. Was any of those
> > assumptions wrong? Besides, is the time used the local time or UTC?
>
>
> looks like you swapped upper and lowercase alphas ...
> see: http://en.wikipedia.org/wiki/Base_62
>


Ah, thank you.

In case anyone cares, here's the corrected version. Just save it as file
ending with .py, make it executable and pass the base 62 number you want
to turn decimal as argument.

#!/usr/bin/python
import sys
def valueOf (letter):
    if (letter.islower()):
        return ord(letter) - 61
    elif (letter.isupper()):
        return ord(letter) - 55
    else:
        return ord(letter) - 48



encoded = sys.argv[1]
decoded = 0
round = 0
for i in range(len(encoded) - 1, -1, -1):
    decoded += valueOf(encoded[i]) * pow (62, round)
    round +=  1


print decoded
#END