コード例 #1
0
    def dec(self, C, seed):

        if type(C) is not BitArray("0"):
            C = BitArray(hex=C)

        random.seed(seed)
        len_S = len(C[:-128])
        #S = BitArray(bin = str(bin(random.getrandbits(len(C[:-128]))))[2:])
        bin_S = bin(random.getrandbits(len_S))[2:]
        S = BitArray(bin="0" * (len_S - len(bin_S)) + bin_S)

        CL = BitArray(bin=C.bin[:-128])
        CR = BitArray(bin=C.bin[-128:])

        L = (S.__xor__(CL)).bin

        k = self.F.calc(self.__MasterKey, self.toBin(L))

        key = self.toBin(BitArray(k).bin)

        Fk = BitArray(hex=md5(self.F.calc(key, S.bin).hex).hexdigest())

        R = (Fk.__xor__(CR)).bin

        X = L + R

        res = self.curata_str(self.toStr(self.E.Decrypt(self.toStr(X))))

        return res
コード例 #2
0
 def generate_coded_symbol(generator_row, message_symbol_list):
     selected_list = [message_symbol_list[i] for i, g in enumerate(generator_row) if g == 1]
     coded_symbol = BitArray( [0] * len(message_symbol_list[0]) )
     for s in selected_list:
         coded_symbol = coded_symbol.__xor__(s)
     
     return coded_symbol
コード例 #3
0
 def generate_coded_symbol(generator_row, message_symbol_list):
     assert (len(generator_row) == len(message_symbol_list))
     
     selected_list = [message_symbol_list[i] for i, g in enumerate(generator_row) if g == 1]
     
     #coded_symbol = bitarray.bitarray('0' * len(message_symbol_list[0]))
     #coded_symbol = BitVector(size = len(message_symbol_list[0]))
     coded_symbol = BitArray( [0] * len(message_symbol_list[0]) )
     for s in selected_list:
         coded_symbol = coded_symbol.__xor__(s)
     
     return coded_symbol
コード例 #4
0
    def enc(self, W, seed):

        X = self.simetric_enc(W)

        L = X.bin[:-128]
        R = X.bin[-128:]

        len_S = len(X.bin[:-128])

        random.seed(seed)
        bin_S = bin(random.getrandbits(len_S))[2:]
        S = BitArray(bin="0" * (len_S - len(bin_S)) + bin_S).bin

        k = self.getKey(X)

        key = self.toBin(BitArray(k).bin)

        Fk = BitArray(hex=md5(self.F.calc(key, S).hex).hexdigest())

        SFk = BitArray(bin=str(S) + Fk.bin)
        c = SFk.__xor__(X)

        return C