Skip to content

Instantly share code, notes, and snippets.

@timseed
Created October 8, 2017 14:03
Show Gist options
  • Select an option

  • Save timseed/8ef894dbad4dedb00c3d902297b772bc to your computer and use it in GitHub Desktop.

Select an option

Save timseed/8ef894dbad4dedb00c3d902297b772bc to your computer and use it in GitHub Desktop.
def str_to_hex_str(s):
out=""
for c in s:
out+= "{:04x}".format(ord(c))
return out
def hex_str_to_str(hs):
out=""
for i in range(0,len(b),4):
out+= chr(int('0x'+hs[i:i+4],16))
return out
test=[U"TTS",U"TاM",U"ااا"]
for word in test:
word_as_hex = str_to_hex_str(word)
word_back = hex_str_to_str(word_as_hex)
if word_back == word:
status="Ok"
else:
status="Bad"
print("{} {} Hex {} Back {} ".format(status,word,word_as_hex,word_back))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment