cryptodome-lab 0.2.0__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cryptodome_lab-0.2.0 → cryptodome_lab-0.2.2}/PKG-INFO +1 -1
- cryptodome_lab-0.2.0/cryptodome_lab/practicals/04_des_ecb_cbc.txt → cryptodome_lab-0.2.2/cryptodome_lab/practicals/04_encryption_des_aes.txt +78 -0
- cryptodome_lab-0.2.0/cryptodome_lab/practicals/09_hmac_sha1.txt → cryptodome_lab-0.2.2/cryptodome_lab/practicals/08_hmac_sha1.txt +35 -10
- {cryptodome_lab-0.2.0 → cryptodome_lab-0.2.2}/cryptodome_lab.egg-info/PKG-INFO +1 -1
- {cryptodome_lab-0.2.0 → cryptodome_lab-0.2.2}/cryptodome_lab.egg-info/SOURCES.txt +7 -8
- {cryptodome_lab-0.2.0 → cryptodome_lab-0.2.2}/pyproject.toml +1 -1
- cryptodome_lab-0.2.0/cryptodome_lab/practicals/05_aes_cbc.txt +0 -76
- {cryptodome_lab-0.2.0 → cryptodome_lab-0.2.2}/README.md +0 -0
- {cryptodome_lab-0.2.0 → cryptodome_lab-0.2.2}/cryptodome_lab/__init__.py +0 -0
- {cryptodome_lab-0.2.0 → cryptodome_lab-0.2.2}/cryptodome_lab/__main__.py +0 -0
- {cryptodome_lab-0.2.0 → cryptodome_lab-0.2.2}/cryptodome_lab/practicals/01_substitution_cipher.txt +0 -0
- {cryptodome_lab-0.2.0 → cryptodome_lab-0.2.2}/cryptodome_lab/practicals/02_vernam_cipher.txt +0 -0
- {cryptodome_lab-0.2.0 → cryptodome_lab-0.2.2}/cryptodome_lab/practicals/03_rail_fence_cipher.txt +0 -0
- /cryptodome_lab-0.2.0/cryptodome_lab/practicals/06_rsa_algorithm.txt → /cryptodome_lab-0.2.2/cryptodome_lab/practicals/05_rsa_algorithm.txt +0 -0
- /cryptodome_lab-0.2.0/cryptodome_lab/practicals/07_diffie_hellman.txt → /cryptodome_lab-0.2.2/cryptodome_lab/practicals/06_diffie_hellman.txt +0 -0
- /cryptodome_lab-0.2.0/cryptodome_lab/practicals/08_md5.txt → /cryptodome_lab-0.2.2/cryptodome_lab/practicals/07_md5.txt +0 -0
- /cryptodome_lab-0.2.0/cryptodome_lab/practicals/10_openssl_implementation.txt → /cryptodome_lab-0.2.2/cryptodome_lab/practicals/09_openssl_implementation.txt +0 -0
- /cryptodome_lab-0.2.0/cryptodome_lab/practicals/11_windows_firewall.txt → /cryptodome_lab-0.2.2/cryptodome_lab/practicals/10_windows_firewall.txt +0 -0
- {cryptodome_lab-0.2.0 → cryptodome_lab-0.2.2}/cryptodome_lab.egg-info/dependency_links.txt +0 -0
- {cryptodome_lab-0.2.0 → cryptodome_lab-0.2.2}/cryptodome_lab.egg-info/top_level.txt +0 -0
- {cryptodome_lab-0.2.0 → cryptodome_lab-0.2.2}/setup.cfg +0 -0
|
@@ -119,3 +119,81 @@ if __name__ == "__main__":
|
|
|
119
119
|
decrypted = decrypt_des(encrypted, key, iv)
|
|
120
120
|
print("Decrypted Message:", decrypted)
|
|
121
121
|
Output:-
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
PRACTICAL NO: 4.2
|
|
125
|
+
AES
|
|
126
|
+
CBC
|
|
127
|
+
CODE:
|
|
128
|
+
from Crypto.Cipher import AES
|
|
129
|
+
from Crypto.Random import get_random_bytes
|
|
130
|
+
import base64
|
|
131
|
+
def pad(data):
|
|
132
|
+
pad_len=16-(len(data)%16)
|
|
133
|
+
return data+chr(pad_len) * pad_len
|
|
134
|
+
def unpad(data):
|
|
135
|
+
pad_len=ord(data[-1])
|
|
136
|
+
return data[:-pad_len]
|
|
137
|
+
def encrypt_aes(palin_text,key):
|
|
138
|
+
iv=get_random_bytes(16)
|
|
139
|
+
cipher=AES.new(key,AES.MODE_CBC,iv)
|
|
140
|
+
padded_text=pad(palin_text)
|
|
141
|
+
encrypted=cipher.encrypt(padded_text.encode('utf-8'))
|
|
142
|
+
return base64.b64encode(iv+encrypted).decode('utf-8')
|
|
143
|
+
def decrypt_aes(cipher_text,key):
|
|
144
|
+
raw=base64.b64decode(cipher_text)
|
|
145
|
+
iv=raw[:16]
|
|
146
|
+
encrypted=raw[16:]
|
|
147
|
+
cipher=AES.new(key,AES.MODE_CBC,iv)
|
|
148
|
+
decrypted=cipher.decrypt(encrypted).decode('utf-8')
|
|
149
|
+
return unpad(decrypted)
|
|
150
|
+
if __name__=="__main__":
|
|
151
|
+
key=get_random_bytes(16)
|
|
152
|
+
print("AES key (base64):",base64.b64encode(key).decode("utf-8"))
|
|
153
|
+
msg="Hello,AES encryption!"
|
|
154
|
+
print("Original msg:",msg)
|
|
155
|
+
encrypted=encrypt_aes(msg,key)
|
|
156
|
+
print("Encrypted (Base64):",encrypted)
|
|
157
|
+
decrypted=decrypt_aes(encrypted,key)
|
|
158
|
+
print("Decrypted (Base64):",decrypted)
|
|
159
|
+
OUTPUT:
|
|
160
|
+
ECB
|
|
161
|
+
CODE:
|
|
162
|
+
from Crypto.Cipher import AES
|
|
163
|
+
from Crypto.Util.Padding import pad,unpad
|
|
164
|
+
key=b'SixteenByteKey12'
|
|
165
|
+
data=b'Secure Database Payload Data'
|
|
166
|
+
cipher_encrypt=AES.new(key,AES.MODE_ECB)
|
|
167
|
+
padded_data=pad(data,AES.block_size)
|
|
168
|
+
ciphertext=cipher_encrypt.encrypt(padded_data)
|
|
169
|
+
cipher_decrypt=AES.new(key,AES.MODE_ECB)
|
|
170
|
+
decrypted_padded=cipher_decrypt.decrypt(ciphertext)
|
|
171
|
+
original_data=unpad(decrypted_padded,AES.block_size)
|
|
172
|
+
print(f"Ciphertext (Hex) : {ciphertext.hex()}")
|
|
173
|
+
print(f"Decrypted Data: {original_data.decode()}")
|
|
174
|
+
OUTPUT:
|
|
175
|
+
from Crypto.Cipher import AES
|
|
176
|
+
from Crypto.Util.Padding import pad, unpad
|
|
177
|
+
from Crypto.Random import get_random_bytes
|
|
178
|
+
key = b"1234567890abcdef"
|
|
179
|
+
iv = get_random_bytes(16)
|
|
180
|
+
input_file = "C:/Users/Admin/Downloads/simple.txt"
|
|
181
|
+
encrypted_file = "encrypted.bin"
|
|
182
|
+
with open(input_file, "rb") as f:
|
|
183
|
+
plaintext = f.read()
|
|
184
|
+
cipher = AES.new(key, AES.MODE_CBC, iv)
|
|
185
|
+
ciphertext = cipher.encrypt(pad(plaintext, AES.block_size))
|
|
186
|
+
with open(encrypted_file, "wb") as f:
|
|
187
|
+
f.write(iv)
|
|
188
|
+
f.write(ciphertext)
|
|
189
|
+
print("File encrypted successfully as:", encrypted_file)
|
|
190
|
+
decrypted_file = "decrypted_file"
|
|
191
|
+
with open(encrypted_file, "rb") as f:
|
|
192
|
+
iv = f.read(16) # Read IV
|
|
193
|
+
ciphertext = f.read() # Read ciphertext
|
|
194
|
+
cipher = AES.new(key, AES.MODE_CBC, iv)
|
|
195
|
+
decrypted_data = unpad(cipher.decrypt(ciphertext), AES.block_size)
|
|
196
|
+
with open(decrypted_file, "wb") as f:
|
|
197
|
+
f.write(decrypted_data)
|
|
198
|
+
print("File decrypted successfully as:", decrypted_file)
|
|
199
|
+
Output:-
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
PRACTICAL NO:8
|
|
2
|
-
|
|
2
|
+
HMAC-SHA1
|
|
3
3
|
Aim
|
|
4
4
|
To write a Python program to calculate the HMAC-SHA1 (Hash-based Message Authentication Code using SHA-1) signature for a given message and secret key.
|
|
5
5
|
Introduction
|
|
@@ -8,12 +8,37 @@ HMAC-SHA1 uses the SHA-1 hash algorithm as its underlying hash function. The res
|
|
|
8
8
|
Need for HMAC
|
|
9
9
|
A normal hash function can detect accidental changes to data, but by itself it does not prove who generated the hash. An attacker who changes a message could also calculate a new ordinary hash. HMAC solves this problem by combining the message with a secret key that is known only to the communicating parties.
|
|
10
10
|
HMAC-SHA1
|
|
11
|
-
In HMAC-SHA1, SHA-1 is used as the hash function. The secret key is
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
In HMAC-SHA1, SHA-1 is used as the hash function. The secret key is processed according to the HMAC construction and combined with the message using two fixed padding values called ipad and opad.
|
|
12
|
+
|
|
13
|
+
8.1 CODE:
|
|
14
|
+
import hmac
|
|
15
|
+
import hashlib
|
|
16
|
+
|
|
17
|
+
msg = input("Enter the message:")
|
|
18
|
+
key = input("Enter the secret key:")
|
|
19
|
+
|
|
20
|
+
msg = msg.encode()
|
|
21
|
+
key = key.encode()
|
|
22
|
+
|
|
23
|
+
hmac_result = hmac.new(key, msg, hashlib.sha1)
|
|
24
|
+
print("HMAC-SHA1 Signature:", hmac_result.hexdigest())
|
|
25
|
+
|
|
26
|
+
8.1 OUTPUT:
|
|
27
|
+
|
|
28
|
+
8.2 CODE:
|
|
29
|
+
import hmac
|
|
30
|
+
import hashlib
|
|
31
|
+
|
|
32
|
+
file_path = input("Enter the path of the text file: ")
|
|
33
|
+
secret_key = input("Enter the secret key: ")
|
|
34
|
+
|
|
35
|
+
with open(file_path, 'r') as file:
|
|
36
|
+
message = file.read()
|
|
37
|
+
|
|
38
|
+
key_bytes = secret_key.encode()
|
|
39
|
+
message_bytes = message.encode()
|
|
40
|
+
|
|
41
|
+
hmac_result = hmac.new(key_bytes, message_bytes, hashlib.sha1)
|
|
42
|
+
print("HMAC-SHA1:", hmac_result.hexdigest())
|
|
43
|
+
|
|
44
|
+
8.2 OUTPUT:
|
|
@@ -9,11 +9,10 @@ cryptodome_lab.egg-info/top_level.txt
|
|
|
9
9
|
cryptodome_lab/practicals/01_substitution_cipher.txt
|
|
10
10
|
cryptodome_lab/practicals/02_vernam_cipher.txt
|
|
11
11
|
cryptodome_lab/practicals/03_rail_fence_cipher.txt
|
|
12
|
-
cryptodome_lab/practicals/
|
|
13
|
-
cryptodome_lab/practicals/
|
|
14
|
-
cryptodome_lab/practicals/
|
|
15
|
-
cryptodome_lab/practicals/
|
|
16
|
-
cryptodome_lab/practicals/
|
|
17
|
-
cryptodome_lab/practicals/
|
|
18
|
-
cryptodome_lab/practicals/
|
|
19
|
-
cryptodome_lab/practicals/11_windows_firewall.txt
|
|
12
|
+
cryptodome_lab/practicals/04_encryption_des_aes.txt
|
|
13
|
+
cryptodome_lab/practicals/05_rsa_algorithm.txt
|
|
14
|
+
cryptodome_lab/practicals/06_diffie_hellman.txt
|
|
15
|
+
cryptodome_lab/practicals/07_md5.txt
|
|
16
|
+
cryptodome_lab/practicals/08_hmac_sha1.txt
|
|
17
|
+
cryptodome_lab/practicals/09_openssl_implementation.txt
|
|
18
|
+
cryptodome_lab/practicals/10_windows_firewall.txt
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
PRACTICAL NO: 4.2
|
|
2
|
-
AES
|
|
3
|
-
CBC
|
|
4
|
-
CODE:
|
|
5
|
-
from Crypto.Cipher import AES
|
|
6
|
-
from Crypto.Random import get_random_bytes
|
|
7
|
-
import base64
|
|
8
|
-
def pad(data):
|
|
9
|
-
pad_len=16-(len(data)%16)
|
|
10
|
-
return data+chr(pad_len) * pad_len
|
|
11
|
-
def unpad(data):
|
|
12
|
-
pad_len=ord(data[-1])
|
|
13
|
-
return data[:-pad_len]
|
|
14
|
-
def encrypt_aes(palin_text,key):
|
|
15
|
-
iv=get_random_bytes(16)
|
|
16
|
-
cipher=AES.new(key,AES.MODE_CBC,iv)
|
|
17
|
-
padded_text=pad(palin_text)
|
|
18
|
-
encrypted=cipher.encrypt(padded_text.encode('utf-8'))
|
|
19
|
-
return base64.b64encode(iv+encrypted).decode('utf-8')
|
|
20
|
-
def decrypt_aes(cipher_text,key):
|
|
21
|
-
raw=base64.b64decode(cipher_text)
|
|
22
|
-
iv=raw[:16]
|
|
23
|
-
encrypted=raw[16:]
|
|
24
|
-
cipher=AES.new(key,AES.MODE_CBC,iv)
|
|
25
|
-
decrypted=cipher.decrypt(encrypted).decode('utf-8')
|
|
26
|
-
return unpad(decrypted)
|
|
27
|
-
if __name__=="__main__":
|
|
28
|
-
key=get_random_bytes(16)
|
|
29
|
-
print("AES key (base64):",base64.b64encode(key).decode("utf-8"))
|
|
30
|
-
msg="Hello,AES encryption!"
|
|
31
|
-
print("Original msg:",msg)
|
|
32
|
-
encrypted=encrypt_aes(msg,key)
|
|
33
|
-
print("Encrypted (Base64):",encrypted)
|
|
34
|
-
decrypted=decrypt_aes(encrypted,key)
|
|
35
|
-
print("Decrypted (Base64):",decrypted)
|
|
36
|
-
OUTPUT:
|
|
37
|
-
ECB
|
|
38
|
-
CODE:
|
|
39
|
-
from Crypto.Cipher import AES
|
|
40
|
-
from Crypto.Util.Padding import pad,unpad
|
|
41
|
-
key=b'SixteenByteKey12'
|
|
42
|
-
data=b'Secure Database Payload Data'
|
|
43
|
-
cipher_encrypt=AES.new(key,AES.MODE_ECB)
|
|
44
|
-
padded_data=pad(data,AES.block_size)
|
|
45
|
-
ciphertext=cipher_encrypt.encrypt(padded_data)
|
|
46
|
-
cipher_decrypt=AES.new(key,AES.MODE_ECB)
|
|
47
|
-
decrypted_padded=cipher_decrypt.decrypt(ciphertext)
|
|
48
|
-
original_data=unpad(decrypted_padded,AES.block_size)
|
|
49
|
-
print(f"Ciphertext (Hex) : {ciphertext.hex()}")
|
|
50
|
-
print(f"Decrypted Data: {original_data.decode()}")
|
|
51
|
-
OUTPUT:
|
|
52
|
-
from Crypto.Cipher import AES
|
|
53
|
-
from Crypto.Util.Padding import pad, unpad
|
|
54
|
-
from Crypto.Random import get_random_bytes
|
|
55
|
-
key = b"1234567890abcdef"
|
|
56
|
-
iv = get_random_bytes(16)
|
|
57
|
-
input_file = "C:/Users/Admin/Downloads/simple.txt"
|
|
58
|
-
encrypted_file = "encrypted.bin"
|
|
59
|
-
with open(input_file, "rb") as f:
|
|
60
|
-
plaintext = f.read()
|
|
61
|
-
cipher = AES.new(key, AES.MODE_CBC, iv)
|
|
62
|
-
ciphertext = cipher.encrypt(pad(plaintext, AES.block_size))
|
|
63
|
-
with open(encrypted_file, "wb") as f:
|
|
64
|
-
f.write(iv)
|
|
65
|
-
f.write(ciphertext)
|
|
66
|
-
print("File encrypted successfully as:", encrypted_file)
|
|
67
|
-
decrypted_file = "decrypted_file"
|
|
68
|
-
with open(encrypted_file, "rb") as f:
|
|
69
|
-
iv = f.read(16) # Read IV
|
|
70
|
-
ciphertext = f.read() # Read ciphertext
|
|
71
|
-
cipher = AES.new(key, AES.MODE_CBC, iv)
|
|
72
|
-
decrypted_data = unpad(cipher.decrypt(ciphertext), AES.block_size)
|
|
73
|
-
with open(decrypted_file, "wb") as f:
|
|
74
|
-
f.write(decrypted_data)
|
|
75
|
-
print("File decrypted successfully as:", decrypted_file)
|
|
76
|
-
Output:-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cryptodome_lab-0.2.0 → cryptodome_lab-0.2.2}/cryptodome_lab/practicals/01_substitution_cipher.txt
RENAMED
|
File without changes
|
{cryptodome_lab-0.2.0 → cryptodome_lab-0.2.2}/cryptodome_lab/practicals/02_vernam_cipher.txt
RENAMED
|
File without changes
|
{cryptodome_lab-0.2.0 → cryptodome_lab-0.2.2}/cryptodome_lab/practicals/03_rail_fence_cipher.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|