-
Notifications
You must be signed in to change notification settings - Fork 0
/
Encrypter.py
51 lines (50 loc) · 1.3 KB
/
Encrypter.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
# -*- coding: utf-8 -*-
# @Author: Krishna
# @Date: 2016-03-13 14:41:06
# @Last Modified by: Krishna
# @Last Modified time: 2016-04-20 12:18:48
import base64
import hashlib
from AESCipher import AESCipher
from Decrypter import Decrypter
from PIL import Image
from random import randint
class Encrypter:
def __init__(self, text, key, splits = None):
self.text = text
self.key = key
print base64.b64encode(key)
if splits is None:
self.splits = 2
else:
self.splits = splits
def generate_splits(self):
aes = AESCipher(self.key)
cipher = aes.encrypt(self.text)
message = aes.decrypt(cipher)
size = 255, len(self.key)
im = Image.new("1", size, "white")
pix = im.load()
for i in range(len(self.key)):
for j in range(ord(self.key[i])):
pix[j, i] = 0
im.save("original.gif")
share1 = Image.new("1", size, "white")
share1pix = share1.load()
for i in range(len(self.key)):
for j in range(255):
x = randint(0,1)
if x == 0:
share1pix[j, i] = 0
share2 = Image.new("1", size)
share2pix = share2.load()
for i in range(len(self.key)):
for j in range(255):
if pix[j, i] == share1pix[j, i]:
share2pix[j, i] = 0
else:
share2pix[j, i] = 255
output = [share1, share2, cipher]
x = Decrypter(cipher, [share1, share2])
x.decrypt_image()
return output