Esempio n. 1
0
def CBC(data,key,mode,iv):
    result=""
    keyarray = f_des.key_schedule(key)
    if mode == "1":
        for i in range(0,len(data),64):
            tmp = f_des.xor_func(data[i:i+64],iv)
            iv = f_des.DES(tmp,keyarray)
            result+=iv
    else:
        for i in range(0,len(data),64):
            tmp = f_des.de_DES(data[i:i+64],keyarray)
            result += f_des.xor_func(tmp,iv)
            iv = data[i:i+64]

    return result
Esempio n. 2
0
def CBC(data, key, mode, iv):
    result = ""
    keyarray = f_des.key_schedule(key)
    if mode == "1":
        for i in range(0, len(data), 64):
            tmp = f_des.xor_func(data[i:i + 64], iv)
            iv = f_des.DES(tmp, keyarray)
            result += iv
    else:
        for i in range(0, len(data), 64):
            tmp = f_des.de_DES(data[i:i + 64], keyarray)
            result += f_des.xor_func(tmp, iv)
            iv = data[i:i + 64]

    return result
Esempio n. 3
0
def OFB(data,key,mode,iv):
    result=""
    keyarray = f_des.key_schedule(key)
    for i in range(0,len(data),64):
        iv = f_des.DES(iv,keyarray)
        result += f_des.xor_func(data[i:i+64],iv)

    return result
Esempio n. 4
0
def OFB(data, key, mode, iv):
    result = ""
    keyarray = f_des.key_schedule(key)
    for i in range(0, len(data), 64):
        iv = f_des.DES(iv, keyarray)
        result += f_des.xor_func(data[i:i + 64], iv)

    return result
Esempio n. 5
0
def CTR(data,key,mode,iv):
    def add_1(d):
        if d == "1"*64:
            return "0"*64
        return bin(int(d,2)+1)[2:].zfill(64)

    result=""
    keyarray = f_des.key_schedule(key)
    for i in range(0,len(data),64):
        iv = add_1(iv)
        tmp = f_des.DES(iv,keyarray)
        result += f_des.xor_func(data[i:i+64],tmp)

    return result
Esempio n. 6
0
def CTR(data, key, mode, iv):
    def add_1(d):
        if d == "1" * 64:
            return "0" * 64
        return bin(int(d, 2) + 1)[2:].zfill(64)

    result = ""
    keyarray = f_des.key_schedule(key)
    for i in range(0, len(data), 64):
        iv = add_1(iv)
        tmp = f_des.DES(iv, keyarray)
        result += f_des.xor_func(data[i:i + 64], tmp)

    return result