-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
60 lines (46 loc) · 1.86 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
import ast
import base64
import numpy as np
from caesar import *
from image import *
from rsaCrypto import *
from openKeys import *
from generateKeys import *
from keysBase64 import *
from PIL import Image
while(True):
decision = input('RSA or Caesar? (r/c)')
if decision is 'r':
decision = input('Generate key, encrypt or decrypt? (g/e/d)')
# generate keys
if decision is 'g':
private, public = generateKeys()
encodeAndSavePrivate(private)
encodeAndSavePublic(public)
# encrypt
if decision is 'e':
openImage('images/lena-greyscale.png').show()
with open('images/lena-greyscale.png', "rb") as imageFile:
image64 = base64.b64encode(imageFile.read()).decode()
# image64 = image64.decode()
public = loadPublicKey()
encrypted = encryptLargeFile(image64, public)
with open('encryptedimg', 'w') as outfile:
outfile.write(str(encrypted))
# decrypt
if decision is 'd':
private = loadPrivateKey()
encrypted = open('encryptedimg', 'r').read()
decryptedVal = decryptLargeFile(encrypted, private)
decryptedBytes = base64.b64decode(decryptedVal)
with open('images/new.png', 'wb') as outfile:
outfile.write(decryptedBytes)
openImage('images/new.png').show()
if decision is 'c':
decision = input('Generate, Encrypt or decrypt? (g/e/d)')
if decision is 'g':
caesarCreate()
if decision is 'e':
cipher('encrypt', 'images/lena-greyscale-small.png', 'images/lena-encrypted-caesar.png')
if decision is 'd':
cipher('decrypt', 'images/lena-encrypted-caesar.png', 'images/lena-decrypted-caesar.png')