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
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
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
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
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
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