コード例 #1
0
ファイル: challenge17.py プロジェクト: ritobanrc/cryptopals
def check_cbc_padding_random(ciphertext, iv):
    ciphertext = bytes(ciphertext)
    iv = bytes(iv)
    try:
        plaintext = aes_cbc_decrypt(ciphertext, random_key, iv)
        return True
    except ValueError:
        return False
コード例 #2
0
ファイル: challenge16.py プロジェクト: ritobanrc/cryptopals
def authenticate(ciphertext):
    plaintext = aes_cbc_decrypt(ciphertext, random_key, random_iv)
    plaintext = strip_pkcs7padding(plaintext)
    info_dict = {}
    for pair in plaintext.split(b';'):
        k, v = pair.split(b'=')
        info_dict[bytes(unquote(k.decode(errors='ignore')), encoding='utf-8')] = \
            bytes(unquote(v.decode(errors='ignore')), encoding='utf-8')
    if b'admin' in info_dict and info_dict[b'admin'] == b'true':
        print('Logged in as admin. ')
        return True, plaintext
    else:
        print('Logged in as regular user')
        return False, plaintext
コード例 #3
0
    def admin_exists(self, ct):
        """
        Detects if the admin parameter has been set to true in an input
        encrypted CT.

        @param ct [str]: Encrypted param string.
        @returns [bool]: True if, when decrypted, the string contains
                         ';admin=true;', False otherwise.
        """
        pt = aes_cbc_decrypt(self.__key, ct, self.__iv)
        vals = [
            tup for tup in [param.split('=') for param in pt.split(';')]
            if len(tup) == 2 and tup[0] == 'admin' and tup[1] == 'true'
        ]
        return len(vals) > 0
コード例 #4
0
def f2(enc, k, iv):
    pt = aes_cbc_decrypt(enc, k, iv)

    return TARGET in pt
コード例 #5
0
 def decrypt(self, ct):
     return aes_cbc_decrypt(self.__key, ct, self.__iv)