[Verba] Re: Nemesis Coding: Taylor's solution completed

Stuart D. Gathman stuart at gathman.org
Mon Jan 23 16:50:43 EST 2006


I have attached a completed version of Taylor's approach.
It is instructive in its own right.

-- 
	      Stuart D. Gathman <stuart at bmsi.com>
Business Management Systems Inc.  Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.
-------------- next part --------------
def decode(s):
  """Decode binary strings to ASCII
  >>> decode('010000100110100101101110011000010111001001111001')
  'Binary'
  """
  n = int(s,2)
  r = []
  while n > 0:
    r.append(chr(n%256))
    n /= 256
  r.reverse()
  return ''.join(r)

def _test():
  import doctest,bin2
  return doctest.testmod(bin2)

# Make into a program that can decode a message from stdin:

if __name__ == '__main__':
  _test()
  import sys
  print decode(sys.stdin.read())


More information about the Verba mailing list