Skip to content

Instantly share code, notes, and snippets.

@dtmsecurity
Created August 7, 2018 10:29
Show Gist options
  • Save dtmsecurity/16728513bb92fe7bdec532be426ef17a to your computer and use it in GitHub Desktop.
Save dtmsecurity/16728513bb92fe7bdec532be426ef17a to your computer and use it in GitHub Desktop.
NETBIOS encode/decode
# Implemented the reverse of the compact answer on:
# https://stackoverflow.com/questions/1965065/encode-netbios-name-python/1965140
def netbios_encode(input_string):
return ''.join([chr((ord(c)>>4)+ord('A'))+chr((ord(c)&0xF)+ord('A')) for c in input_string])
def netbios_decode(netbios):
i = iter(netbios.upper())
try:
return ''.join([chr(((ord(c)-ord('A'))<<4)+((ord(next(i))-ord('A'))&0xF)) for c in i])
except:
return ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment