Пример #1
0
    def test_random_key(self):
        """ Creates random X byte aes key """
        key = aestools.random_key(16)
        keytwo = aestools.random_key(16)
        keythree = aestools.random_key(5)

        self.assertEqual(len(key), 16)
        self.assertEqual(len(keythree), 5)
        self.assertNotEqual(key, keytwo)
Пример #2
0
    def test_challenge_20(self):
        """ Challenge 20: Break fixed-nonce CTR Statistically """

        key = aestools.random_key(16)
        nonce = bytes(8)
        input_file = open('files/20.txt', 'r')
        lines = [conv.base_64_to_bytes(line.rstrip()) for line in input_file]
        input_file.close()
        encrypted_lines = [aestools.do_ctr(line, key, nonce) for line in lines]
        min_length = min([len(line) for line in encrypted_lines])
        concatted = b''.join([line[0:min_length] for line in encrypted_lines])
        test = xortools.breakxor(concatted, min_length)
Пример #3
0
    def test_challenge_19(self):
        """ Challenge 19: Break fixed-nonce CTR """

        key = aestools.random_key(16)
        nonce = bytes(8)
        input_file = open('files/19.txt', 'r')
        lines = [conv.base_64_to_bytes(line.rstrip()) for line in input_file]
        input_file.close()
        encrypted_lines = [aestools.do_ctr(line, key, nonce) for line in lines]

        index = 0
        probable_bytes = bytearray()
        while(True):
            rotated = "".join([chr(line[index]) if index < len(line) else '' for line in encrypted_lines])
            b, all, score = xortools.solve_xor_block(bytes(rotated, 'utf-8'))
            probable_bytes.append(b)
            index += 1
            if len(rotated) == 0: break

        for line in encrypted_lines:
            close = xortools.xor_bytes(line, bytes(probable_bytes[0 : len(line)]))
            readable = " ".join([chr(b) if b in range(32, 127) else 'X' for b in close])
Пример #4
0
 def test_get_prefix(self):
     function = aestools.get_black_box(True)
     for prefix_length in range(0, 128):
         aestools.PREFIX = aestools.random_key(prefix_length)
         blocksize, length, padding = aestools.get_block_size_and_length(function)
         self.assertEqual(aestools.get_prefix_length(function, blocksize, length, padding), prefix_length)
Пример #5
0
    return encode(create_or_get_user(email, role))

def profile_for(email, role='user'):
    encoded_profile = profile(email, role)
    return aestools.encrypt_ecb(bytes(encoded_profile, 'UTF-8'), KEY, True)

def parse_encrypted(bytes):
    return aestools.decrypt_ecb(bytes, KEY, True)

def create_or_get_user(email, role='user'):
    if email not in USERS:
        USERS[email] = User(email, role)

    return USERS[email]

KEY = aestools.random_key(16)

class User():
    nextid = 0

    def getNextId(self):
        User.nextid += 1
        return User.nextid

    def __init__(self, email, role='user'):
        self.email = email
        self.role = role
        self.id = self.getNextId()

    def items(self):
        ordereddict = OrderedDict()