def dec(str): str = normalize(str) return ''.join(chr(int(binary, 2)) for binary in str.split(' ')) def enc(str): return ' '.join(bin(ord(char)).split('b')[1].rjust(8, '0') for char in str) def normalize(str): str = str.replace(' ', '') return " ".join(str[i:i+8] for i in range(0, len(str), 8)) str = "00110000 00110001 00110000 00110001 00110001 00110001 00110000 00110000 00100000 00110000 00110001 00110001 00110000 00110001 00110001 00110000 00110001 00100000 00110000 00110000 00110001 00110000 00110001 00110001 00110001 00110001" if (len(str) > 0): print "decoding.. %s" % str decoded = dec(str) try: print "once: " print decoded print "2x: " print dec(decoded) except: pass ## PASTE MESSAGE TO ENCODE HERE ## toencode = "" if (len(toencode) > 0): ## encode? print '-' * 80 print 'ENCODER:' print "encoding \"%s\"" % toencode print "encoded once:" encoded = enc(toencode) print encoded print "encoded 2x:" double_encoded = enc(encoded) print double_encoded print "\nEND"
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question