-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
87 lines (73 loc) · 2.6 KB
/
main.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from saes import SimplifiedAES
from double_saes import DoubleSimplifiedAES
from triple_saes import TripleSimplifiedAES_mode1, TripleSimplifiedAES_mode2
from utils import decimal_to_16bit_binary, ascii_encrypt, ascii_decrypt
# 3.1 & 3.2
plaintext = 0b0000111100001111
key = 0b0010110101010101
ciphertext = SimplifiedAES(key).encrypt(plaintext) # 0b0010010011101100
# print(decimal_to_16bit_binary(ciphertext))
print(decimal_to_16bit_binary(ciphertext))
ciphertext = 0b0010010011101100
key = 0b0010110101010101
plaintext = SimplifiedAES(key).decrypt(ciphertext) # 0b1101011100101000
print(bin(plaintext))
# 3.3
# 创建SAES实例,使用16位密钥
# key = 0b0100101011110101
# saes = SimplifiedAES(key)
#
# # 要加密的ASCII字符串,每个字符表示为一个16位整数
# plaintext_ascii = "Hello SAES"
# plaintext_integers = [ord(char) for char in plaintext_ascii]
#
# # 加密
# encrypted_integers, binary_encrypted_integers = ascii_encrypt(plaintext_ascii, saes)
# # 输出加密后的整数
# print("Encrypted Integers:", binary_encrypted_integers)
#
# # 解密
# decrypted_integers = [saes.decrypt(encrypted_int) for encrypted_int in encrypted_integers]
# # 将解密后的整数转换回ASCII字符串
# decrypted_ascii = ascii_decrypt(encrypted_integers, saes)
#
# # 输出解密后的ASCII字符串
# print("Decrypted ASCII:", decrypted_ascii)
# 3.4.1
plaintext = 0b0000111100001111
key = 0b00101101010101010010110101010101
# 创建DoubleSimplifiedAES实例
double_aes = DoubleSimplifiedAES(key)
# 加密
ciphertext = double_aes.encrypt(plaintext)
print("加密后的密文:", decimal_to_16bit_binary(ciphertext))
# 解密
decrypted_plaintext = double_aes.decrypt(ciphertext)
print("解密后的明文:", decimal_to_16bit_binary(decrypted_plaintext))
# 3.4.3
# mode 1
# 使用32位密钥进行三重加密
# key1 = 0b0100101011110101
# key2 = 0b1101011100101000
# triple_aes = TripleSimplifiedAES_mode1(key1, key2)
#
# plaintext = 0b0000111100001111
# ciphertext = triple_aes.encrypt(plaintext)
# print("加密后的密文:", decimal_to_16bit_binary(ciphertext))
#
# decrypted = triple_aes.decrypt(ciphertext)
# print("解密后的明文:", decimal_to_16bit_binary(decrypted))
#
# # mode 2
# # 使用48位密钥进行三重加密
# key1 = 0b0100101011110101
# key2 = 0b1101011100101000
# key3 = 0b1111000011110000
# triple_aes = TripleSimplifiedAES_mode2(key1, key2, key3)
#
# plaintext = 0b0000111100001111
# ciphertext = triple_aes.encrypt(plaintext)
# print("加密后的密文:", decimal_to_16bit_binary(ciphertext))
#
# decrypted = triple_aes.decrypt(ciphertext)
# print("解密后的明文:", decimal_to_16bit_binary(decrypted))