-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.py
executable file
·69 lines (59 loc) · 1.66 KB
/
image.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
'''
from Crypto.Cipher import AES
import base64
# the 'key' and the 'iv' is taken from the terminal after running aes_test.py
# key = 'gKdldH6lj9gEtb59Cr9lSsWNv7xFo5yr'
# iv = 'qUDmobVJ1vOGTvmS'
# def dec(data):
key = 'a'*32;
iv = 'b'*16;
enc_s = AES.new(key, AES.MODE_CFB, iv)
cipher_text = enc_s.encrypt("secret")
encoded_cipher_text = base64.b64encode(cipher_text)
decryption_suite = AES.new(key, AES.MODE_CFB, iv)
plain_text = decryption_suite.decrypt(base64.b64decode(encoded_cipher_text))
# return plain_text
print(plain_text)
'''
'''
import pyAesCrypt
from os import stat, remove
# encryption/decryption buffer size
bufferSize = 64 * 1024
password = 'pwd'# encryption of file data.txt
with open('photo.jpg', 'rb') as fIn:
with open('photo.jpg.aes', 'wb') as fOut:
pyAesCrypt.encryptStream(fIn, fOut, password, bufferSize)# get encrypted file size
encFileSize = stat('photo.jpg.aes').st_size
print(encFileSize) #prints file size# decryption of file data.aes
with open('photo.jpg.aes', 'rb') as fIn:
with open('photo_out.jpg', 'wb') as fOut:
try:
# decrypt file stream
pyAesCrypt.decryptStream(fIn, fOut, password, bufferSize, encFileSize)
except ValueError:
# remove output file on error
remove('photo_out.txt')
'''
'''
fo = open('hostx.jpg', 'rb')
image = fo.read()
fo.close()
image = bytearray(image)
key = 32
for index, value in enumerate(image):
image[index] = value^key
fo = open('hostx_enc.jpg', 'wb')
fo.write(image)
fo.close()
'''
fo = open('hostx_dec.jpg', 'rb')
image = fo.read()
fo.close()
image = bytearray(image)
key = 32
for index, value in enumerate(image):
image[index] = value^key
fo = open('hostx_re.jpg', 'wb')
fo.write(image)
fo.close()