Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/usr/bin/python
  2. def overlongify(char):
  3.     byteseq = [0xc0,0xe0,0xf0,0xf8,0xfc]
  4.     end_byte = 0x80
  5.     end = 0x80 + (char & 0x3f) # clear top 2 bits (for all sequences)
  6.     print "char [%c] dec [%d] hex [%02x] url: %%%02x"%(chr(char), char, char, char)
  7.        
  8.     for i in xrange(0, len(byteseq)):
  9.         start = byteseq[i] + (char >> 6) # we only need the top 2 bits
  10.         print "overlong %d-byte sequence: %02x"%(i+2, start),
  11.         if (i > 1):
  12.             for j in xrange(0, i):
  13.                 print "80",
  14.         print "%02x"%end                                                                      
  15.  
  16. def run():
  17.     while(1):    
  18.         x = raw_input("Enter an ASCII char to make overlong, or hex (ex: h27) or 'quit': ")
  19.         if (x.lower() == "quit"):
  20.             break
  21.         if (len(x) > 1 and not x.startswith('h')):
  22.             print "You must enter a single character."
  23.             continue
  24.         if (x.startswith('h')):
  25.             x = x[1:].decode("hex")
  26.         overlongify(ord(x))
  27.  
  28. if __name__ == '__main__':
  29.     print "overlongyourmom.py written by wirepair"
  30.     run()