Exemple #1
0
    def test_unit_aes192_cbc_16(self):
        ciphertext = bytes.fromhex("c8adab3e8b72d1cba934605fe2e9e156")

        c = CipherBase(KEY_24, self.cipher, MODES.CBC.value, IV)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #2
0
    def test_unit_blowfish_cfb_16(self):
        ciphertext = bytes.fromhex("fc5b2dd3b30096cd77c262eebc99dd80")

        c = CipherBase(KEY, self.cipher, MODES.CFB.value, iv=self.iv)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #3
0
    def test_unit_cast_ecb_16(self):
        ciphertext = bytes.fromhex("553dc819236b01cea730534ce9b937ea")

        c = CipherBase(KEY, self.cipher, MODES.ECB.value)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #4
0
    def test_unit_blowfish_ecb_16(self):
        ciphertext = bytes.fromhex("fb45bb1ca8037a7b6ebc4f5e84bb3baf")

        c = CipherBase(KEY, self.cipher, MODES.ECB.value)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #5
0
    def test_unit_blowfish_cbc_16(self):
        ciphertext = bytes.fromhex("ad458ee703990278986d635889d45847")

        c = CipherBase(KEY, self.cipher, MODES.CBC.value, iv=self.iv)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #6
0
    def test_unit_aes128_ecb_16(self):
        ciphertext = bytes.fromhex("4d724eb675dcad2609db02bc73bcfdac")

        c = CipherBase(KEY, self.cipher, MODES.ECB.value)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #7
0
    def test_unit_DES_cfb(self):
        ciphertext = bytes.fromhex("59c7ca572f41542776cbc33df2fe4bf1")

        c = CipherBase(KEY_8, self.cipher, MODES.CFB.value, iv=self.iv)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #8
0
    def test_unit_arc2_cbc_16(self):
        ciphertext = bytes.fromhex("d4d54eb37cc62088995c46d27ab51489")

        c = CipherBase(KEY, self.cipher, MODES.CBC.value, iv=self.iv)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #9
0
    def test_unit_arc2_cfb_16(self):
        ciphertext = bytes.fromhex("4094c8f3f5a4caa25e522cdff62d80b3")

        c = CipherBase(KEY, self.cipher, MODES.CFB.value, iv=self.iv)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #10
0
    def test_unit_aes256_cfb_16(self):
        ciphertext = bytes.fromhex("a0bc499e0f4a9b38c5fd6b41f6bca972")

        c = CipherBase(KEY_32, self.cipher, MODES.CFB.value, IV)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #11
0
    def test_unit_arc2_ecb_16(self):
        ciphertext = bytes.fromhex("f3ca1b6a3d91281cff5cf38b82eda1eb")

        c = CipherBase(KEY, self.cipher, MODES.ECB.value)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #12
0
    def test_unit_aes256_cbc_16(self):
        ciphertext = bytes.fromhex("c5bfe450f78df3783b9f90634fb531b9")

        c = CipherBase(KEY_32, self.cipher, MODES.CBC.value, IV)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #13
0
    def test_unit_aes256_ecb_16(self):
        ciphertext = bytes.fromhex("e9deb75428c3601527a330c092cd27e9")

        c = CipherBase(KEY_32, self.cipher, MODES.ECB.value)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #14
0
    def test_unit_aes192_cfb_16(self):
        ciphertext = bytes.fromhex("1e60d3038a0358d94bf3c87ba11faade")

        c = CipherBase(KEY_24, self.cipher, MODES.CFB.value, IV)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #15
0
    def test_unit_cast_cfb_16(self):
        ciphertext = bytes.fromhex("5c4a37efd91aa5087d2233c0ade7179e")

        c = CipherBase(KEY, self.cipher, MODES.CFB.value, iv=self.iv)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #16
0
    def test_unit_arc4_ecb_16(self):
        ciphertext = bytes.fromhex("a07bf3d83927f0d298e087f2c18a15f1")

        c = CipherBase(KEY, self.cipher, MODES.ECB.value)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #17
0
    def test_unit_DES_ecb(self):
        ciphertext = bytes.fromhex("a754cc262554afa485e5bf43a0118974")

        c = CipherBase(KEY_8, self.cipher, MODES.ECB.value)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #18
0
    def test_unit_arc4_cbc_16(self):
        ciphertext = bytes.fromhex("68e28f521dfbdf89eb8ef6dc8c149e60")

        c = CipherBase(KEY, self.cipher, MODES.CBC.value)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #19
0
    def test_unit_DES_cbc(self):
        ciphertext = bytes.fromhex("2ad4b705a34ec7b6bb0d16b6009c31ca")

        c = CipherBase(KEY_8, self.cipher, MODES.CBC.value, iv=self.iv)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #20
0
    def test_unit_cast_cbc_16(self):
        ciphertext = bytes.fromhex("e187a66ef5167e971ce558342ac2937d")

        c = CipherBase(KEY, self.cipher, MODES.CBC.value, iv=self.iv)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #21
0
    def test_unit_aes192_ecb_16(self):
        ciphertext = bytes.fromhex("ece49f9be7367048ea37c7574eb227a2")

        c = CipherBase(KEY_24, self.cipher, MODES.ECB.value)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #22
0
    def test_unit_aes128_cfb_16(self):
        ciphertext = bytes.fromhex("0c13ae7eec29a7b73c7fe64768a9f4d6")

        c = CipherBase(KEY, self.cipher, MODES.CFB.value, IV)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #23
0
def checkEnc(padded_plaintext, ciphertext, cipher, mode, iv=None):
    """
    Helper method to check the cipher text produced by the encryption equals the given cipher text
    """
    cipherObj = None
    if iv == None:
        cipherObj = CipherBase(key, cipher, mode)
    else:
        if mode != MODES.ECB.value:
            cipherObj = CipherBase(key, cipher, mode, iv)
        else:
            return False

    try:
        enc = cipherObj.encrypt(padded_plaintext)
        return ciphertext == enc

    # Handles PyCryptos 3DES
    except ValueError as e:
        if e.args[0] != "Triple DES key degenerates to single DES":
            raise e
        else:
            print(
                f"[*] {cipher.__name__} - {MODES(mode)} - INFO: Triple DES key degenerates to single DES because both sides of the keys are equal"
            )
            return False
Exemple #24
0
    def test_unit_3DES_cfb_16(self):
        ciphertext = bytes.fromhex("3258e421fbe3c4f984a3803d8135c04e")

        c = CipherBase(KEY, self.cipher, MODES.CFB.value, iv=self.iv)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #25
0
    def test_unit_aes128_cbc_16(self):
        ciphertext = bytes.fromhex("2fc1bd060a70aaab5d13ffdbaa495202")

        c = CipherBase(KEY, self.cipher, MODES.CBC.value, IV)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #26
0
    def test_unit_3DES_cfb_24(self):
        ciphertext = bytes.fromhex("6ac546089bd5c0243edb02df8c634236")

        c = CipherBase(KEY_24, self.cipher, MODES.CFB.value, self.iv)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #27
0
    def test_unit_3DES_cbc_24(self):
        ciphertext = bytes.fromhex("d9d6d1e52d2d1aca3dc5d40344c4c7ff")

        c = CipherBase(KEY_24, self.cipher, MODES.CBC.value, self.iv)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #28
0
    def test_unit_3DES_ecb_16(self):
        ciphertext = bytes.fromhex("b4a13de834e5508d775ea54e2e924888")

        c = CipherBase(KEY, self.cipher, MODES.ECB.value)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #29
0
    def test_unit_3DES_cbc_16(self):
        mode = MODES.CBC.value
        ciphertext = bytes.fromhex("e86517ad7bfbe8ae3e14715baba2a31b")

        c = CipherBase(KEY, self.cipher, mode, iv=self.iv)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)
Exemple #30
0
    def test_unit_3DES_ecb_24(self):
        mode = MODES.ECB.value
        ciphertext = bytes.fromhex("8f463cbd36dd263ffe8520e572978f31")

        c = CipherBase(KEY_24, self.cipher, mode)
        e = c.encrypt(self.plaintext)

        self.assertEqual(e, ciphertext)