Exemplo n.º 1
0
def encode_topic(topic, key):
    blowfish.initialize(key)

    instring = topic
    blocks = len(instring) / 8
    padding = (blocks + 1) * 8 - len(instring)
    instring = instring + padding * chr(padding)
    print "Padding with %s bytes" % padding

    outstring = ""

    print "Encrypting..."
    for i in range(blocks + 1):
        inbytes = blowfish.mkchunk(instring[i * 8:i * 8 +
                                            8])  # 8-byte string as hex no.
        cipher = blowfish.bfencrypt(inbytes)  # ...encrypted
        outbytes = "%016X" % cipher
        outstring = outstring + outbytes  # and appended

    topic = ""
    print "Size: %s / %s" % (len(instring), len(outstring))
    print '"%s"' % outstring
    for i in range(0, len(outstring), 2):
        if i > 0: topic = topic + "%3B"
        topic = topic + '%d' % hex2num(outstring[i:i + 2])

    return '%5B' + topic + '%5D'
def encode_topic(topic,key):
    blowfish.initialize(key)

    instring = topic
    blocks = len(instring)/8
    padding = (blocks + 1)*8 - len(instring)
    instring = instring + padding * chr(padding)
    print "Padding with %s bytes" % padding

    outstring = ""

    print "Encrypting..."
    for i in range(blocks+1):
        inbytes   = blowfish.mkchunk(instring[i*8:i*8+8])   # 8-byte string as hex no.
        cipher    = blowfish.bfencrypt(inbytes)             # ...encrypted
        outbytes  = "%016X" % cipher
        outstring = outstring + outbytes                    # and appended

    topic = ""
    print "Size: %s / %s" % (len(instring),len(outstring))
    print '"%s"' % outstring
    for i in range(0,len(outstring),2):
        if i>0: topic = topic + "%3B"
        topic = topic + '%d' % hex2num(outstring[i:i+2])

    return '%5B'+topic+'%5D'
Exemplo n.º 3
0
def encode_topics(topics, key):
    key = blowfish.mkchunk(key)
    topics = topics.split(',')
    ret = ""

    j = 0
    for topic in topics:
        if j > 0:
            ret = ret + '%2C'
        ret = ret + encode_topic(topic.encode("ISO-8859-1"), key)
        j = j + 1

    return ret
def encode_topics(topics,key):
    key = blowfish.mkchunk(key)
    topics = topics.split(',')
    ret = ""

    j=0
    for topic in topics:
        if j>0:
            ret = ret + '%2C'
        ret = ret + encode_topic(topic.encode("ISO-8859-1"),key)
        j = j + 1

    return ret