Last active
January 1, 2022 14:55
-
-
Save xavierskip/2a5d386ab58f59402327bdac42f31273 to your computer and use it in GitHub Desktop.
Cover your words, covert your string to 8-bit binary style
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
#!/usr/bin/env python2 | |
# coding: utf-8 | |
def cover(words, separator=' '): | |
return separator.join(['{:0>8}'.format(bin(ord(w))[2:]) for w in words]) | |
def recover(words, separator=' '): | |
return ''.join([chr(int(b,2)) for b in words.split(separator)]) | |
if __name__ == '__main__': | |
words = '你好世界,hello world' | |
bin_words = cover(words) | |
print(bin_words) | |
recover_words = recover(bin_words) | |
print(recover_words) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in python3