forked from prashantbarca/LeAmitVPN
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathamitcrypto.py
More file actions
38 lines (29 loc) · 1.01 KB
/
Copy pathamitcrypto.py
File metadata and controls
38 lines (29 loc) · 1.01 KB
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
from Crypto.Cipher import XOR
from Crypto.Cipher import AES
key = b"abcdefghijklmnop"
iv = b"abcdefghijklmnop"
def enc(sock, message, addr):
sock.sendto(abcd, addr)
sock.sendto(abcd, addr)
return abcd
def dec(sock, message, addr):
abcd = xor1.decrypt(message)
return abcd
abcd = xor.encrypt(message)
print message == dec(sock, abcd, addr)
sock.sendto(abcd, addr)
pad_len = 16 - len(message) % 16
padded = message + (chr(pad_len) * pad_len)
cipher = AES.new(key, AES.MODE_CBC, iv)
abcd = cipher.encrypt(padded)
sock.sendto(abcd, addr)
return abcd
def dec(sock, message, addr):
if len(message) % 16 != 0:
raise ValueError("Invalid message length")
cipher = AES.new(key, AES.MODE_CBC, iv)
decrypted_padded = cipher.decrypt(message)
pad_len = ord(decrypted_padded[-1])
if pad_len < 1 or pad_len > 16 or decrypted_padded[-pad_len:] != (chr(pad_len) * pad_len):
raise ValueError("Invalid padding")
return decrypted_padded[:-pad_len]