Otra:
Code:
import numpy
class binParser:
def __init__(self, binlength=8, space=True, encodeSpace=True):
self.binlen=binlength
self.trailingspace=space
self.encodeSpace=encodeSpace
def toBin(message):
result = ""
for char in message:
if self.encodeSpace==False and char==" ": break
result += numpy.binary_repr(ord(char),self.binlen)
if self.trailingspace: result += " "
return result
def fromBin(message):
result=""
splitList = message.split()
for binChar in splitList:
result += chr(int(binchar,2))
return result
if __name__ == "__main__":
parser = binParser()
print "test:", parser.fromBin(parser.toBin("test"))