Created
August 7, 2018 10:29
-
-
Save dtmsecurity/16728513bb92fe7bdec532be426ef17a to your computer and use it in GitHub Desktop.
NETBIOS encode/decode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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