#!/usr/bin/python
def overlongify(char):
byteseq = [0xc0,0xe0,0xf0,0xf8,0xfc]
end_byte = 0x80
end = 0x80 + (char & 0x3f) # clear top 2 bits (for all sequences)
print "char [%c] dec [%d] hex [%02x] url: %%%02x"%(chr(char), char, char, char)
for i in xrange(0, len(byteseq)):
start = byteseq[i] + (char >> 6) # we only need the top 2 bits
print "overlong %d-byte sequence: %02x"%(i+2, start),
if (i > 1):
for j in xrange(0, i):
print "80",
print "%02x"%end
def run():
while(1):
x = raw_input("Enter an ASCII char to make overlong, or hex (ex: h27) or 'quit': ")
if (x.lower() == "quit"):
break
if (len(x) > 1 and not x.startswith('h')):
print "You must enter a single character."
continue
if (x.startswith('h')):
x = x[1:].decode("hex")
overlongify(ord(x))
if __name__ == '__main__':
print "overlongyourmom.py written by wirepair"
run()