Created
October 8, 2017 14:03
-
-
Save timseed/8ef894dbad4dedb00c3d902297b772bc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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