Exemplo n.º 1
0
def ofb_decrypt(cipher, key, iv):
    blocks = split_to_blocks(cipher)
    result = ""
    for block in blocks:
        iv = des_encrypt(iv, key)
        bin_iv = plaintobin(iv)
        bin_block = plaintobin(block)
        xored = binary_string(xor(bin_block, bin_iv, 64))
        result += xored
    return result
Exemplo n.º 2
0
def cbc_encrypt(plain, key, iv):
    blocks = split_to_blocks(plain)
    result = ""
    for block in blocks:
        bin_block = plaintobin(block)
        bin_iv = plaintobin(iv)
        xored = binary_string(xor(bin_block, bin_iv, 64))
        iv = des_encrypt(xored, key)
        result += iv
    return result
Exemplo n.º 3
0
def cfb_encrypt(plain, key, iv):
    blocks = split_to_blocks(plain)
    result = ""
    for block in blocks:
        enc_iv = des_encrypt(iv, key)
        bin_iv = plaintobin(enc_iv)
        bin_block = plaintobin(block)
        xored = binary_string(xor(bin_block, bin_iv, 64))
        iv = xored
        result += xored
    return result
Exemplo n.º 4
0
def ctr_decrypt(cipher, key, nunce):
    ctr = 0
    blocks = split_to_blocks(cipher)
    result = ""
    for block in blocks:
        bin_nunce = plaintobin(nunce)
        bin_ctr = '{0:064b}'.format(ctr)
        new_nunce = binary_string(xor(bin_nunce, bin_ctr, 64))
        enc_ctr = des_encrypt(new_nunce, key)
        bin_enc = plaintobin(enc_ctr)
        bin_block = plaintobin(block)
        xored = binary_string(xor(bin_enc, bin_block, 64))
        ctr += 1
        result += xored
    return result
Exemplo n.º 5
0
def ecb_encrypt(plain, key):
    blocks = split_to_blocks(plain)
    result = ""
    for block in blocks:
        result += des_encrypt(block, key)
    return result