Search code examples
pythonnetbios

encode Netbios name python


I would like to encode "ITSATEST" to it's netbios name value in python; The occurence table and explication are here: http://support.microsoft.com/kb/194203

I dont know how this could be done easily in python, someone can give me a hand ?

Thanks !


Solution

  • You can map each nibble of the original string, taking its numerical value and offsetting from 'A':

    encoded_name = ''.join([chr((ord(c)>>4) + ord('A'))
                            + chr((ord(c)&0xF) + ord('A')) for c in original_name])