Question

I'm trying to create a simple script that will convert a string (max 15 chars) to a netbios name (see http://support.microsoft.com/kb/194203) :

name = sys.argv[1].upper()
converted = ''.join([chr((ord(c)>>4) + ord('A'))+chr((ord(c)&0xF) + ord('A')) for c in name])
print converted

Trying to convert the name : "testing" will return : "4645454646444645454a454f4548" which is correct. Now depending the length of the name submitted (max 15 chars) we need to pad 4341 until the converted string is 64 long. Example :

./script.py testing:
4645454646444645454a454f4548

But should actually be : 4645454646444645454a454f4548434143414341434143414341434143414341

Anyways to do this easily ?

Thanks !

Was it helpful?

Solution

... + ((16 - len(name)) * '4341')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top