-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_04_b_TripleDES2Key.py
36 lines (27 loc) · 1.14 KB
/
A_04_b_TripleDES2Key.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Author: Devashish Roy, Roll No: 2024PGCSIS08
# Assignment No: 04
# Implementation of Standard Symmetric Block Ciphers
# a) Data Encryption Standard (DES)
# b) Triple DES
# c) Advance Encryption Standard (AES)
# Triple DES with 2 Keys
import A_04_a_DES as DES
def tripleDESEncryption(plaintext, key1, key2):
return DES.desEncryption(DES.desDecryption(DES.desEncryption(plaintext, key1), key2), key1)
def tripleDESDecryption(ciphertext, key1, key2):
return DES.desDecryption(DES.desEncryption(DES.desDecryption(ciphertext, key1), key2), key1)
if __name__ == "__main__":
plaintext = "ABCD132536654321"
plaintext = DES.hexToBin(plaintext)
key1 = "4133957999BDCCF9"
key1 = DES.hexToBin(key1)
key2 = "4133957999BDCCF2"
key2 = DES.hexToBin(key2)
print("Plaintext:", DES.binToHex(plaintext), "Key1:", DES.binToHex(key1), "Key2:", DES.binToHex(key2))
print()
ciphertext = tripleDESEncryption(plaintext, key1, key2)
print("Encryption:")
print("Ciphertext:", DES.binToHex(ciphertext))
print()
print("Decryption: ")
print("Plaintext:", DES.binToHex(tripleDESDecryption(ciphertext, key1, key2)), "\n")