Пример #1
0
    def testEncriptDecript(self):
        plainText = 'idjpi23j023uc0j1-0i-soxl=kixq[wkz=21ks[qqwdqwd'
        password = '******'
        encodedText = aes.encode(password, plainText)
        decodedText = aes.decode(password, encodedText)

        self.assertEqual(decodedText, plainText)
Пример #2
0
def decode(k, p):
    p_len = len(p)
    block = 16
    str_tmp = '{:0>2x}'.format(p[0])
    c_str = ''
    for i in range(1, p_len):
        if i % block == 0:
            c_str += aes.decode(str_tmp, k)
            str_tmp = '{:0>2x}'.format(p[i])
        else:
            str_tmp = str_tmp + '{:0>2x}'.format(p[i])
    c_str += aes.decode(str_tmp, k)
    c_len = len(c_str)
    res = bytes.fromhex(c_str)
    res_len = len(res)
    pad = res[res_len - 1]
    return res[:res_len - pad]
Пример #3
0
def decode_password_base(master_password):
    """
    Tries to decode the password base using passed master password
    Returns 0 if decoding failed, otherwise returns decoded data
    """
    with open(PASSWORD_BASE_PATH, 'rb+') as data_file:
        encoded_data_bytes = data_file.read()
        encoded_data_str = encoded_data_bytes.decode()
        decoded_data_str = aes.decode(master_password, encoded_data_str)
        try:
            data = json.loads(decoded_data_str)
            return data
        except json.decoder.JSONDecodeError:
            return 0
Пример #4
0
def decode(k, p, IV):
    p_len = len(p)
    block = 16
    p_str = ''
    nr = p_len // block
    for i in range(p_len):
        p_str += '{:0>2x}'.format(p[i])

    c_str = ''
    c_nr = IV
    for i in range(nr):
        c_nr = str_xor_16(aes.decode(p_str[i * 32:i * 32 + 32], k), c_nr)
        c_str += c_nr
        c_nr = p_str[i * 32:i * 32 + 32]
    res = bytes.fromhex(c_str)
    res_len = len(res)
    pad = res[res_len - 1]
    return res[:res_len - pad]
Пример #5
0
 def ui_de(self):
     c = self.cInput.get().strip()
     k = self.kInput.get().strip()
     self.pInput.delete(0, END)
     lc = len(c)
     lk = len(k)
     if lp != 32:
         tkinter.messagebox.showwarning('Waring',
                                        'The length of c is wrong!')
     else:
         if lk == 32:
             p = aes.decode(c, k)
             self.pInput.insert(10, str(p))
         elif lk == 48:
             p = aes.encode(p, k, 6, 12)
             self.pInput.insert(10, str(p))
         elif lk == 64:
             p = aes.encode(p, k, 8, 14)
             self.pInput.insert(10, str(p))
         else:
             tkinter.messagebox.showwarning('Waring',
                                            'The length of key is wrong!')