Skip to content

Instantly share code, notes, and snippets.

@miettal
Last active December 7, 2015 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miettal/38bd9f07baa80a0e18a2 to your computer and use it in GitHub Desktop.
Save miettal/38bd9f07baa80a0e18a2 to your computer and use it in GitHub Desktop.
text = open('./no-network.txt').read().replace('\n', '')
utf9_array = []
i = 0
print len(text)
while i < len(text) :
utf9 = (int(text[i])<<6) + (int(text[i+1])<<3) + int(text[i+2])
utf9_array.append(utf9)
i += 3
i = 0
print len(utf9_array)
ucs4_array = []
while i < len(utf9_array) :
nonet = utf9_array[i]; i+=1
ucs4 = nonet & 0xff
while nonet & 0x100 :
ucs4 <<= 8;
nonet = utf9_array[i]; i+=1
ucs4 |= nonet & 0xff
ucs4_array.append(ucs4)
i = 0
byte_array = ''
print len(ucs4_array)
while i < len(ucs4_array) :
byte_array += unichr(ucs4_array[i]).encode('utf-8')
i += 1
print len(byte_array)
print byte_array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment