forked from ravi5175/IAWT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
key_io.py
55 lines (48 loc) · 1.31 KB
/
key_io.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
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 7 19:23:34 2020
Project-Image_Authentication_Using_Water_Marking_Technique
Section-Key_I/0
@author: RAVI
"""
import sys
import math
import itertools
import random
from PIL import Image
def shuffle_order(size, shuffle_seed):
order = []
for i in range (size):
order.append(i)
if (shuffle_seed):
random.seed(shuffle_seed)
shuffled = random.shuffle(order)
return order
else:
return order
def encrypt(plain, key):
cipher = []
k = 0
len_key = len(key)
len_plain = len(plain)
for i in range(len_plain):
cipher.append((plain[i] + ord(key[i % len_key])) % 256)
return cipher
def decrypt(cipher, key):
plain = []
k = 0
len_key = len(key)
len_cipher = len(cipher)
for i in range(len_cipher):
plain.append((cipher[i] + 256 - ord(key[i % len_key])) % 256)
return plain
def rms(image_a,image_b):
px_a = image_a.load()
px_b = image_b.load()
sum=0;
for i in range(image_a.width):
for j in range(image_a.height):
p_a = px_a[i,j]
p_b = px_b[i,j]
sum += math.pow((p_a[0] - p_b[0]), 2) + math.pow((p_a[1] - p_b[1]), 2) + math.pow((p_a[2] - p_b[2]), 2)
return 5#math.sqrt(sum / (image_a.width * image_a.height) / 3)