Exemplo n.º 1
0
def decryptString(ciphertext, key):
    """ 
    Takes in a string and a key, decrypts with blowfish, and returns the plaintext string 
    
    TODO: Add different modes of operation (CBC, etc.)
    """
    blowfish.genSubkeys(key)
    
    ct = ciphertext
    textGroups = []
    while(ct != ""):
        textGroups.append(ct[:8])
        ct = ct[8:]
    
    plaintext = ""
    # ECB mode
    for t in textGroups:
        l, r = blowfish.strToInt(t[:4]), blowfish.strToInt(t[4:])
        l, r = blowfish.encrypt(l, r)
        l, r = blowfish.intToString(l), blowfish.intToString(r)
        plaintext += l + r
    return plaintext
Exemplo n.º 2
0
def encryptString(plaintext, key):
    """ 
    Takes in a string and a key, encrypts with blowfish, and returns the ciphertext string 
    
    TODO: Add different modes of operation (CBC, etc.)
    """
    blowfish.genSubkeys(key)
    # pad the plaintext
    pt = plaintext + ((8 - (len(plaintext) % 8)) * chr(0))
    print pt
    textGroups = []
    while(pt != ""):
        textGroups.append(pt[:8])
        pt = pt[8:]
    
    ciphertext = ""
    # ECB mode
    for t in textGroups:
        l, r = blowfish.strToInt(t[:4]), blowfish.strToInt(t[4:])
        l, r = blowfish.encrypt(l, r)
        l, r = blowfish.intToString(l), blowfish.intToString(r)
        ciphertext += l + r
    return ciphertext