├── .gitignore ├── Chaos ├── Check.py ├── Convert.py ├── Decryption.py ├── Encryption.py ├── Key.py ├── XInitial.py ├── Xn.py ├── YInitial.py ├── Yn.py └── __init__.py ├── ImageAnalyserTool.py ├── bifurcation.py ├── coplot.py ├── correlationcofficient.py ├── cryptotiger.bmp ├── gui.py ├── histogram.py ├── meansquareerror.py ├── npcr.py ├── readme.md ├── requirements.txt ├── tiger.bmp └── uaci.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### JetBrains template 3 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 4 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 5 | 6 | # User-specific stuff: 7 | .idea/workspace.xml 8 | .idea/tasks.xml 9 | .idea 10 | *.pyc 11 | __pycache__ 12 | *__pycache__ 13 | 14 | # Sensitive or high-churn files: 15 | .idea/dataSources/ 16 | .idea/dataSources.ids 17 | .idea/dataSources.xml 18 | .idea/dataSources.local.xml 19 | .idea/sqlDataSources.xml 20 | .idea/dynamic.xml 21 | .idea/uiDesigner.xml 22 | 23 | # Gradle: 24 | .idea/gradle.xml 25 | .idea/libraries 26 | 27 | # Mongo Explorer plugin: 28 | .idea/mongoSettings.xml 29 | 30 | ## File-based project format: 31 | *.iws 32 | 33 | ## Plugin-specific files: 34 | 35 | # IntelliJ 36 | /out/ 37 | 38 | # mpeltonen/sbt-idea plugin 39 | .idea_modules/ 40 | 41 | # JIRA plugin 42 | atlassian-ide-plugin.xml 43 | 44 | # Crashlytics plugin (for Android Studio and IntelliJ) 45 | com_crashlytics_export_strings.xml 46 | crashlytics.properties 47 | crashlytics-build.properties 48 | fabric.properties 49 | ### macOS template 50 | *.DS_Store 51 | .AppleDouble 52 | .LSOverride 53 | 54 | # Icon must end with two \r 55 | Icon 56 | 57 | 58 | # Thumbnails 59 | ._* 60 | 61 | # Files that might appear in the root of a volume 62 | .DocumentRevisions-V100 63 | .fseventsd 64 | .Spotlight-V100 65 | .TemporaryItems 66 | .Trashes 67 | .VolumeIcon.icns 68 | .com.apple.timemachine.donotpresent 69 | 70 | # Directories potentially created on remote AFP share 71 | .AppleDB 72 | .AppleDesktop 73 | Network Trash Folder 74 | Temporary Items 75 | .apdisk 76 | -------------------------------------------------------------------------------- /Chaos/Check.py: -------------------------------------------------------------------------------- 1 | """ 2 | This file consist of all the modules of the operation to be performed on each pixel.There are 8 operation from 1 to 8. 3 | Each operation has different functionalities to modify the pixel values.Operations are named as operatiions are named as 4 | operation_1,operation_2,operation_3,operation_4,operation_5,operation_6,operation_7,operation_8.This file has a 5 | check_operations_to_be_performed(y_value,r_value,g_value,b_value,binary_keys,decryption=False) which decides which operation to 6 | be performed on the pixels.It has five parameters where y_value->this is obtained by running yn.py file.r_value->red value fetched 7 | from the pixel of the image.g_value->green value fetched from the pixel of the image.b_value->blue value fetched 8 | from the pixel of the image. 9 | 10 | check_operations_to_be_performed(y_value,r_value,g_value,b_value,binary_keys,decryption=False) returns decimal values 11 | after performing the operation on the pixel. 12 | 13 | This function can be called just by passing values of all the parameters. 14 | 15 | """ 16 | 17 | from Chaos.Yn import * 18 | from Chaos.Convert import * 19 | 20 | 21 | count=[0,0,0,0,0,0,0,0,0] 22 | 23 | ## This module has all the rules associated with yn and r,g,b values for encryption and decryption 24 | 25 | def check_operations_to_be_performed(y_value,r_value,g_value,b_value,binary_keys,decryption=False): 26 | if 0 <= y_value < 0.13 or 0.34 <= y_value < 0.37 or 0.58 <= y_value < 0.62: #operation 1 27 | count[0] += 1 28 | return operation_1(r_value, g_value, b_value) 29 | 30 | elif 0.13 <= y_value < 0.16 or 0.37 <= y_value < 0.40 or 0.62 <= y_value < 0.66: #operation 2 31 | count[1] += 1 32 | return operation_2(r_value, g_value, b_value, binary_keys, i=3, j=4, k=5) 33 | 34 | elif 0.16 <= y_value < 0.19 or 0.40 <= y_value < 0.43 or 0.66 <= y_value < 0.70: #operation 3 35 | count[2] += 1 36 | return operation_3(r_value, g_value, b_value, binary_keys, decryption, i=3, j=4, k=5) 37 | 38 | elif 0.19 <= y_value < 0.22 or 0.43 <= y_value < 0.46 or 0.70 <= y_value < 0.74: #operation 4 39 | count[3] += 1 40 | return operation_4(r_value, g_value, b_value, binary_keys, decryption, i=3, j=4, k=5) 41 | 42 | elif 0.22 <= y_value < 0.25 or 0.46 <= y_value < 0.49 or 0.74 <= y_value < 0.78: #operation 5 43 | count[4] += 1 44 | return operation_5(r_value, g_value, b_value, binary_keys, i=6, j=7, k=8) 45 | 46 | elif 0.25 <= y_value < 0.28 or 0.49 <= y_value < 0.52 or 0.78 <= y_value < 0.82: #operation 6 47 | count[5] += 1 48 | return operation_6(r_value, g_value, b_value, binary_keys, decryption, i=6, j=7, k=8) 49 | 50 | elif 0.28 <= y_value < 0.31 or 0.52 <= y_value < 0.55 or 0.82 <= y_value < 0.86: #operation 7 51 | count[6] += 1 52 | return operation_7(r_value, g_value, b_value, binary_keys, decryption, i=6, j=7, k=8) 53 | 54 | elif 0.31 <= y_value < 0.34 or 0.55 <= y_value < 0.58 or 0.86 <= y_value <= 1: #operation 8 55 | count[7] += 1 56 | return [r_value % 256, g_value % 256, b_value % 256] 57 | else: 58 | count[8] += 1 59 | return [r_value%256,g_value%256,b_value%256] 60 | 61 | 62 | 63 | ### Performs NOT operation on a given binary string and returns the resultant binary string 64 | def NOT(binary_value): 65 | s = binary_value 66 | return s.replace('0','2').replace('1','0').replace('2','1') 67 | 68 | 69 | 70 | # Takes r,g and b values in int and returns a list of these values respectively as a list[r,g,b] after performing a NOT operation 71 | def operation_1(r_value,g_value,b_value): 72 | values = [] 73 | r = NOT(int_to_binary_string(r_value)) 74 | g = NOT(int_to_binary_string(g_value)) 75 | b = NOT(int_to_binary_string(b_value)) 76 | r = binary_string_to_int(r) 77 | g = binary_string_to_int(g) 78 | b = binary_string_to_int(b) 79 | 80 | values.append(r) 81 | values.append(g) 82 | values.append(b) 83 | 84 | return values 85 | 86 | 87 | # Takes r,g ,b values in int and binary_keys and returns a list of these values respectively as a list[r,b,g] after modding 88 | def operation_2(r_value,g_value,b_value,binary_keys,i=3,j=4,k=5): 89 | values = [] 90 | values.append((r_value ^ binary_list_to_int(binary_keys[i]))) #modding here because values go above 256 91 | values.append((g_value ^ binary_list_to_int(binary_keys[j]))) 92 | values.append((b_value ^ binary_list_to_int(binary_keys[k]))) 93 | return values 94 | 95 | 96 | # Takes r,g ,b values in int and binary_keys and returns a list of these values respectively as a list[r,b,g] after modding 97 | def operation_3(r_value,g_value,b_value,binary_keys,decryption=False,i=3,j=4,k=5): 98 | values = [] 99 | k4 = binary_list_to_int(binary_keys[i]) 100 | k5 = binary_list_to_int(binary_keys[j]) 101 | k6 = binary_list_to_int(binary_keys[k]) 102 | 103 | if decryption == False: 104 | values.append((r_value + k4+ k5) % 256) 105 | values.append((g_value + k5 + k6) % 256) 106 | values.append((b_value + k6 + k4) % 256) 107 | elif decryption == True: 108 | values.append((r_value + 256 - k4 - k5)%256) #modding here because values go above 256 109 | values.append((g_value + 256 - k5 - k6)%256) 110 | values.append((b_value + 256 - k6 - k4)%256) 111 | 112 | 113 | return values 114 | 115 | # Takes r,g ,b values in int and binary_keys and returns a list of these values respectively as a list[r,b,g] after modding 116 | def operation_4(r_value,g_value,b_value,binary_keys,decryption=False,i=3,j=4,k=5): 117 | values = [] 118 | k4 = binary_list_to_int(binary_keys[i]) 119 | k5 = binary_list_to_int(binary_keys[j]) 120 | k6 = binary_list_to_int(binary_keys[k]) 121 | if decryption == False: 122 | values.append((binary_string_to_int(NOT(int_to_binary_string(r_value^k4))))%256) 123 | values.append((binary_string_to_int(NOT(int_to_binary_string(g_value^k5))))%256) 124 | values.append((binary_string_to_int(NOT(int_to_binary_string(b_value^k6))))%256) 125 | elif decryption == True: 126 | values.append((binary_string_to_int(NOT(int_to_binary_string(r_value)))^k4)%256) #modding here because values go above 256 127 | values.append((binary_string_to_int(NOT(int_to_binary_string(g_value)))^k5)%256) 128 | values.append((binary_string_to_int(NOT(int_to_binary_string(b_value)))^k6)%256) 129 | 130 | 131 | return values 132 | 133 | # Takes r,g ,b values in int and binary_keys and returns a list of these values respectively as a list[r,b,g] after modding 134 | def operation_5(r_value,g_value,b_value,binary_keys,i=6,j=7,k=8): 135 | values = [] 136 | values.append(r_value ^ binary_list_to_int(binary_keys[i])) 137 | values.append(g_value ^ binary_list_to_int(binary_keys[j])) 138 | values.append(b_value ^ binary_list_to_int(binary_keys[k])) 139 | return values 140 | 141 | 142 | # Takes r,g ,b values in int and binary_keys and returns a list of these values respectively as a list[r,b,g] after modding 143 | def operation_6(r_value,g_value,b_value,binary_keys,decryption=False,i=6,j=7,k=8): 144 | values = [] 145 | k4 = binary_list_to_int(binary_keys[i]) 146 | k5 = binary_list_to_int(binary_keys[j]) 147 | k6 = binary_list_to_int(binary_keys[k]) 148 | if decryption == False: 149 | values.append((r_value + k4 + k5) % 256) 150 | values.append((g_value + k5 + k6) % 256) 151 | values.append((b_value + k6 + k4) % 256) 152 | elif decryption == True: 153 | values.append((r_value + 256 - k4 - k5) % 256) # modding here because values go above 256 154 | values.append((g_value + 256 - k5 - k6) % 256) 155 | values.append((b_value + 256 - k6 - k4) % 256) 156 | 157 | 158 | return values 159 | 160 | 161 | # Takes r,g ,b values in int and binary_keys and returns a list of these values respectively as a list[r,b,g] after modding 162 | def operation_7(r_value,g_value,b_value,binary_keys,decryption=False,i=6,j=7,k=8): 163 | values = [] 164 | k4 = binary_list_to_int(binary_keys[i]) 165 | k5 = binary_list_to_int(binary_keys[j]) 166 | k6 = binary_list_to_int(binary_keys[k]) 167 | if decryption == False: 168 | values.append((binary_string_to_int(NOT(int_to_binary_string(r_value^k4))))%256) 169 | values.append((binary_string_to_int(NOT(int_to_binary_string(g_value^k5))))%256) 170 | values.append((binary_string_to_int(NOT(int_to_binary_string(b_value^k6))))%256) 171 | elif decryption == True: 172 | values.append((binary_string_to_int(NOT(int_to_binary_string(r_value)))^k4)%256) #modding here because values go above 256 173 | values.append((binary_string_to_int(NOT(int_to_binary_string(g_value)))^k5)%256) 174 | values.append((binary_string_to_int(NOT(int_to_binary_string(b_value)))^k6)%256) 175 | 176 | 177 | return values 178 | 179 | # Takes r,g ,b values in int and returns a list of these values respectively as a list[r,b,g] after modding 180 | def operation_8(r_value,g_value,b_value): 181 | values = [] 182 | values.append(r_value) 183 | values.append(g_value) 184 | values.append(b_value) 185 | return values 186 | 187 | 188 | # This function takes all the binary keys and return a new set of binary keys without modifying the 10th key 189 | def modifying_session_keys(binary_keys): 190 | new_session_keys = [] 191 | for i in range(0, 9): 192 | new_key = (binary_list_to_int(binary_keys[i]) + binary_list_to_int(binary_keys[9])) % 256 193 | new_session_keys.append(int_to_binary_list(new_key)) 194 | 195 | new_session_keys.append(binary_keys[9]) 196 | return new_session_keys 197 | 198 | 199 | 200 | 201 | 202 | 203 | ###TEST CODE 204 | ####################################################################### 205 | ## This test code tests all the functions defined and conversion codes 206 | ## check_operations_to_be_performed(.78) 207 | 208 | 209 | # binary_keys = to_8bit_keys('ankit12345') 210 | # print("RGB = 128,64,219") 211 | # print("Operation..1") 212 | # print(operation_1(128,64,219)) 213 | # print("Operation..1 to get back values:") 214 | # print(operation_1(127, 36, 191)) 215 | # print("Operation..2") 216 | # print(operation_2(128,64,219,binary_keys)) 217 | # print("Operation..2 to get back values:") 218 | # print(operation_2(233, 52, 234,binary_keys)) 219 | # print("Operation..3") 220 | # print(operation_3(128,64,219,binary_keys)) 221 | # print(operation_3(93,229,117,binary_keys,decryption=True)) 222 | # print("Operation..4") 223 | # print(operation_4(128,64,219,binary_keys)) 224 | # print(operation_4(22,203,21,binary_keys,decryption=True)) 225 | # print("Operation..5") 226 | # print(operation_5(128,64,219,binary_keys)) 227 | # print(operation_5(178,115,239,binary_keys)) 228 | # print("Operation..6") 229 | # print(operation_6(128,64,219,binary_keys)) 230 | # print(operation_6(229,167,65,binary_keys,decryption=True)) 231 | # print("Operation..7") 232 | # print(operation_7(128,64,219,binary_keys)) 233 | # print(operation_7(77,140,16,binary_keys,decryption=True)) 234 | # print("Operation..8") 235 | # print(operation_8(128,64,219)) 236 | # 237 | # print(binary_list_to_int(binary_keys[3])) 238 | # print(binary_list_to_int(binary_keys[4])) 239 | # print(binary_list_to_int(binary_keys[5])) 240 | # # 241 | # r_value = 191 242 | # 243 | # 244 | # print("Coverting int to binary string:",int_to_binary_string(191)) 245 | # print("Coverting binary string to binary list:",binary_string_to_binary_list(int_to_binary_string(191))) 246 | # print("Coverting binary list to binary string:",binary_list_to_binary_string(['1', '0', '1', '1', '1', '1', '1', '1'])) 247 | # print("Coverting binary string to int:",binary_string_to_int('10111111')) 248 | # print("Coverting binary list to int:",binary_list_to_int(['1', '0', '1', '1', '1', '1', '1', '1'])) 249 | # 250 | # 251 | # print(check_operations_to_be_performed(.22,128,64,110,binary_keys)) 252 | # print(check_operations_to_be_performed(.22,22, 203, 160,binary_keys,decryption=True)) 253 | 254 | -------------------------------------------------------------------------------- /Chaos/Convert.py: -------------------------------------------------------------------------------- 1 | """ 2 | This module contains all the code for functions used for conversion from one type to another 3 | It has 6 modules which converts from one data-type to another. For example if you want to convert 4 | an integer value say 9 to binary string then simply call the function like int_to_binary_string(9) 5 | ,this will return binary string so store this into a variable. 6 | """ 7 | 8 | ## converts an integer value directly to a 8-bit binary sting 9 | def int_to_binary_string(int_value): 10 | return '00000000'[len(bin(int_value)[2:]):]+bin(int_value)[2:] 11 | 12 | ## converts an integer value directly to a 8-bit binary array 13 | def int_to_binary_list(int_value): 14 | return list('00000000'[len(bin(int_value)[2:]):]+bin(int_value)[2:]) 15 | 16 | ## converts a 8-bit binary string value directly to a 8-bit binary array 17 | def binary_string_to_binary_list(binary_string): 18 | return list(binary_string) 19 | 20 | ## converts a 8-bit binary array directly to a 8-bit binary sting 21 | def binary_list_to_binary_string(list_of_binary_values): 22 | return (''.join(list_of_binary_values)) 23 | 24 | ## converts a 8-bit binary array directly to integer value 25 | def binary_list_to_int(list_of_binary_values): 26 | return int(''.join(list_of_binary_values), 2) 27 | 28 | ## converts a 8-bit binary string directly to integer value 29 | def binary_string_to_int(binary_string): 30 | return int((binary_string),2) 31 | 32 | 33 | -------------------------------------------------------------------------------- /Chaos/Decryption.py: -------------------------------------------------------------------------------- 1 | """ 2 | Importing all the required modules for decryption function to work.This file has a major module defined as 3 | decrypt module.This module is used to decrypt the image with the secret key.Secret key can be fetched be from the 4 | input field of GUI.Decrypt module has two parameters image file and secret key.encrypted iage file is the location 5 | of the file.Image location is fetched in the module and converted to rgb pixel values. 6 | 7 | you call the decrypt function by calling decrypt(location of image as c://folder_name/file_name).This module returns 8 | the decrypted image so we need to store this into a variable to save the image file 9 | """ 10 | from PIL import Image 11 | from Chaos.Yn import * 12 | from Chaos.Check import * 13 | from Chaos.Encryption import * 14 | 15 | 16 | ## This function uses all the functions of previous modules, takes an encrypted image file and a 80 bit ascii key provided by the user 17 | ## and returns an decrypted image object 18 | 19 | def decrypt(encrypted_image_file , secret_key_80bits): 20 | image = Image.open(encrypted_image_file, "r").convert("RGB") 21 | 22 | pixel_count = 0 23 | 24 | #loading of the pixels as rgb(0-255,0-255,0-255) 25 | pixels = image.load() 26 | width, height = image.size 27 | #print(image.size) 28 | 29 | #conversion of secret key(ASCII of alpha numeric values) to 8 bit binary values) 30 | binary_keys = to_8bit_keys(secret_key_80bits) 31 | 32 | # conversion of secret key(ASCII of alpha numeric values) to hex values 33 | hex_keys = to_hex_keys(secret_key_80bits) 34 | 35 | #calculating xnot values by x01 and x02 module as parameter 36 | x_knot = x0(x01(binary_keys), x02(hex_keys)) 37 | 38 | #generating 24 uniques numbers from 0-1 39 | f24 = xn(x_knot, 24) 40 | 41 | #converting the generated unique number to real number using a formula mentioned in the research paper 42 | p24 = pk(f24) 43 | 44 | y_knot = y0(y01(binary_keys), y02(binary_keys, p24)) 45 | 46 | #fetching last character of secret key 47 | k10 = binary_list_to_int(binary_keys[9]) 48 | 49 | 50 | for coordinate_of_y in range(0, height): 51 | for coordinate_of_x in range(0, width): 52 | #modifying session after 16 pixels 53 | if pixel_count % 16 == 0: 54 | binary_keys = modifying_session_keys(binary_keys) 55 | f24 = xn(f24[23]) 56 | 57 | p24 = pk(f24) 58 | 59 | y_knot = y0(y01(binary_keys), y02(binary_keys, p24)) 60 | 61 | 62 | yn_values = yn(y_knot, k10) 63 | 64 | for i in range(len(yn_values)-1,-1,-1): 65 | value = yn_values[i] 66 | #storing the converted r,g,b values to the same index 67 | r, g, b = check_operations_to_be_performed(value, pixels[coordinate_of_x, coordinate_of_y][0], pixels[coordinate_of_x, coordinate_of_y][1], pixels[coordinate_of_x, coordinate_of_y][2], 68 | binary_keys, decryption=True) 69 | 70 | pixels[coordinate_of_x, coordinate_of_y] = (r, g, b) 71 | 72 | y_knot = yn_values[len(yn_values) - 1] 73 | pixel_count += 1 74 | 75 | #print(count) 76 | return image 77 | 78 | 79 | 80 | 81 | 82 | 83 | ## Test code 84 | ###################################################################### 85 | ## Here we test the decryption modules by creating an image object and loading the image to be decrypted 86 | ## Then we use the decrypt() function to decrypt the image using the key 87 | ## The decrypted image object is then saved at the output directory specified 88 | 89 | # im = encrypt("encrypted/tiger_ankit12345.png","ankit12345") 90 | # 91 | # im.show() 92 | # im.save("decrypted/decrypted.jpg") 93 | 94 | -------------------------------------------------------------------------------- /Chaos/Encryption.py: -------------------------------------------------------------------------------- 1 | """ 2 | PIL (Python Imaging Library) module is used to perform image manipulations 3 | Importing all the required modules for encryption function to work.This file has a major module defined as 4 | encrypt module.This module is used to encrypt the image with the secret key.Secret key can be fetched be from the 5 | input field of GUI.Encrypt module has two parameters image file and secret key.Image file is the location 6 | of the file.Image location is fetched in the module and converted to rgb pixel values. 7 | 8 | you call the decrypt function by calling encrypt(location of image as c://folder_name/file_name).This module returns 9 | the encrypted image so we need to store this into a variable to save the image file 10 | 11 | 12 | """ 13 | from PIL import Image 14 | from Chaos.Yn import * 15 | from Chaos.Check import * 16 | import time 17 | #from numba import jit 18 | 19 | ## Importing all the previous modules 20 | 21 | 22 | 23 | ## This function uses all the functions of previous modules, takes an image file and a 80 bit ascii key provided by the user 24 | ## and returns an encrypted image object 25 | 26 | def encrypt(image_file , secret_key_80bits): 27 | start_time = time.time() #start time of this module 28 | image = Image.open(image_file,"r").convert("RGB") # converting of the image into rgb values 29 | 30 | pixel_count = 0 31 | # loading of the pixels as rgb(0-255,0-255,0-255) 32 | pixels = image.load() 33 | width, height = image.size 34 | #print(image.size) 35 | 36 | 37 | # conversion of secret key(ASCII of alpha numeric values) to 8 bit binary values) 38 | binary_keys = to_8bit_keys(secret_key_80bits) 39 | 40 | # conversion of secret key(ASCII of alpha numeric values) to hex values 41 | hex_keys = to_hex_keys(secret_key_80bits) 42 | 43 | x_knot = x0(x01(binary_keys), x02(hex_keys)) 44 | 45 | # generating 24 uniques numbers from 0-1 46 | f24 = xn(x_knot, 24) 47 | 48 | # converting the generated unique number to real number using a formula mentioned in the research paper 49 | p24 = pk(f24) 50 | 51 | y_knot = y0(y01(binary_keys), y02(binary_keys, p24)) 52 | 53 | k10 = binary_list_to_int(binary_keys[9]) 54 | 55 | 56 | for coordinate_of_y in range(0, height): 57 | for coordinate_of_x in range(0, width): 58 | # modifying session after 16 pixels 59 | if pixel_count%16 == 0: 60 | binary_keys = modifying_session_keys(binary_keys) 61 | f24 = xn(f24[23]) 62 | 63 | p24 = pk(f24) 64 | 65 | y_knot = y0(y01(binary_keys), y02(binary_keys, p24)) 66 | 67 | 68 | yn_values = yn(y_knot, 20) 69 | 70 | for value in yn_values: 71 | # storing the converted r,g,b values to the same index 72 | r,g,b = check_operations_to_be_performed(value,pixels[coordinate_of_x,coordinate_of_y][0],pixels[coordinate_of_x,coordinate_of_y][1],pixels[coordinate_of_x,coordinate_of_y][2],binary_keys,decryption=False) 73 | 74 | pixels[coordinate_of_x,coordinate_of_y] = (r,g,b) 75 | 76 | y_knot = yn_values[len(yn_values) - 1] 77 | pixel_count += 1 78 | 79 | 80 | 81 | 82 | print(count) 83 | print("--- %s seconds ---" % (time.time() - start_time)) 84 | return image 85 | 86 | 87 | 88 | ##Test code 89 | ###################################################################### 90 | ## Here we test the encryption modules by creating an image object and loading the image to be encrypted 91 | ## Then we use the encrypt() function to encrypt the image using the key 92 | ## The encrypted image object is then saved at the output directory specified 93 | 94 | # im = encrypt("images/tiger.jpg","ankit12345") 95 | # 96 | # im.show() 97 | # im.save("encrypted/encrypted.jpg") 98 | # 99 | -------------------------------------------------------------------------------- /Chaos/Key.py: -------------------------------------------------------------------------------- 1 | """ This module helps in key generation process Our key consists of minimum 10 characters of ASCII.It has two modules. 2 | to_8bit_keys_80bits(secret_key_80bits)-This module converts alphanumeric characters to ASCII values and then to binary values 3 | ,the converted binary values is the padded with 8-bit 0 values. 4 | 5 | to_hex_keys(secret_key_80bits)->This module converts alphanumeric characters to ASCII values and then to hex values 6 | 7 | """ 8 | 9 | # This function takes a key string of 10 characters(80 bit) for example: password12 and returns a list of 8 8bit keys in the form of list 10 | # accessing a bit number 2 of key3 will be keys[2][1] 11 | def to_8bit_keys(secret_key_80bits): 12 | keys = [] 13 | for i in range(0,10): 14 | #ord() module converts alphanumeric character to ASCII value 15 | #bin() module converts to binary values 16 | bits = bin(ord(secret_key_80bits[i]))[2:] 17 | binary_value = '00000000'[len(bits):]+bits 18 | keys.append(list(binary_value)) 19 | 20 | return keys 21 | 22 | # This function takes a key string of 10 characters(80 bit) for example: password12 and returns a list of 20 hexadecimal value of each letter in key string 23 | # accessing the first hex value of 2nd character of key string will be keys[3] 24 | def to_hex_keys(secret_key_80bits): 25 | keys = [] 26 | for i in range(0,10): 27 | # ord() module converts alphanumeric character to ASCII value 28 | # hex() module converts to hex values 29 | hexa = hex(ord(secret_key_80bits[i]))[2:] 30 | hex_value = hexa 31 | keys.extend(hex_value) 32 | return keys 33 | 34 | 35 | 36 | ## Test Code 37 | ##################################################################### 38 | ## This code tests this module by converting 10 ascii characters to 10 8-bits key and 20 hexadecimal keys 39 | 40 | # binary_keys = to_8bit_keys('ankit12345') 41 | # hex_keys = to_hex_keys('ankit12345') 42 | # print(binary_keys) 43 | # print(len(binary_keys)) 44 | # print(hex_keys) 45 | # print(len(hex_keys)) 46 | # 47 | -------------------------------------------------------------------------------- /Chaos/XInitial.py: -------------------------------------------------------------------------------- 1 | # importing all the functions from Key module 2 | from Chaos.Key import * 3 | 4 | # This module contains all the functions required to compute the value of X0 5 | # The value of X01 and X02 will computed first using the functions x01 and x02 6 | # Then we add the value of X01 and X02 and mod it with 1 to get the value of X0 7 | 8 | 9 | # This function takes list of 10 binary keys and 3 key index to return X01 value after evaluation 10 | # It converts the 3 given keys into a binary string B1 of 24 bits 11 | # Using B1 we calculate the value of X01 12 | def x01(binary_keys,i=3,j=4,k=5): 13 | B1 = binary_keys[i] + binary_keys[j] + binary_keys[k] 14 | x01 = 0 15 | for i in range(0,len(B1)): 16 | x01 = int(B1[i])*(2**(i)) + x01 17 | 18 | x01 = x01/(2**(24)) 19 | return x01 20 | 21 | # This function takes 20 hexadecimal keys and starting hexadecimal key index (value should be below 15) to compute X02 22 | def x02(hex_keys, i=12): 23 | x02=0 24 | for i in range(i,i+6): 25 | x02 = int(hex_keys[i],16) + x02 26 | 27 | x02 = x02/(96) 28 | return x02 29 | 30 | 31 | # This function mods the value generated by x01() and x02() function by 1 32 | 33 | def x0(x01,x02): 34 | return (x01+x02)%1 35 | 36 | 37 | ## Test code 38 | ###################################################################### 39 | ## Ths is a test code to compute x0 using functions x01() and x02() and the Key module 40 | 41 | # 42 | # binary_keys = to_8bit_keys('ankit12345') 43 | # hex_keys = to_hex_keys('ankit12345') 44 | # for key in binary_keys: 45 | # print(key) 46 | # x1=x01(binary_keys,3,4,5) 47 | # print(x01(binary_keys,3,4,5)) 48 | # 49 | # 50 | # print(hex_keys) 51 | # x2 = x02(hex_keys,12) 52 | # print(x2) 53 | # 54 | # x0 = x0(x1, x2) 55 | # 56 | # print(x0) 57 | -------------------------------------------------------------------------------- /Chaos/Xn.py: -------------------------------------------------------------------------------- 1 | # Importing all the functions from XInitial module 2 | from Chaos.XInitial import * 3 | from PIL import Image 4 | # This module uses the first logistic map and the value obtained from the XInitial modules. 5 | # It iterates until we get 24 real number values that lie between 0.1 and 0.9. 6 | # The above values are then converted into 24 integer values using a function pk. 7 | 8 | 9 | 10 | # This function takes initial value of Xn (i.e. X0 calculated using XInitial module) and iterates until 24 real number values that lie between 0.1 and 0.9 are obtained. 11 | # This function returns a list of 24 real numbers 12 | def xn(XInitial,number_of_values=24): 13 | xn = XInitial 14 | f24 = list() 15 | while len(f24) maxit / 2: 27 | image.putpixel((point_of_x, int(x * imgy)), (0, 0, 255)) 28 | if 3.6 < r < 4: 29 | image.putpixel((point_of_x, int(x * imgy)), (1, 154, 210)) 30 | 31 | image.save("bifurcation.png") 32 | image.show() 33 | 34 | -------------------------------------------------------------------------------- /coplot.py: -------------------------------------------------------------------------------- 1 | """ 2 | this module consists of two module co-plot_horizontal() and co-plot_vertical().These module draws the graph of pearson's 3 | correlation coefficient.Correlation coefficient is the relation between two variable.Here two variables refers to the 4 | two adjacent pixel of a image.Adjacent pixel could be vertically and horizontally 5 | 6 | Two libraries have been used which are pillow as PIL and matplotlib to put relation values to a graph 7 | 8 | co-plot module can be used by just passing the location of the image and location of the output image. 9 | """ 10 | 11 | import matplotlib.pyplot as plt 12 | 13 | from PIL import Image 14 | 15 | def coplot_horizontal(loc,output): 16 | image = Image.open(loc) 17 | 18 | #loading of pixels as rgb 19 | pixels=image.load() 20 | list_of_pixels_of_x=[] 21 | list_of_pixels_of_y=[] 22 | 23 | width,height=image.size 24 | 25 | #running for loop to traverse all the pixel values of the image 26 | for pixel_coordinate_of_y in range(0,50): 27 | for pixel_coordinate_of_x in range(0,50): 28 | 29 | #adding pixel value to a list 30 | list_of_pixels_of_x.append(pixels[pixel_coordinate_of_x,pixel_coordinate_of_y][0]) 31 | if pixel_coordinate_of_x+1 == width: 32 | list_of_pixels_of_x.pop() 33 | break 34 | else: 35 | # adding pixel value to a list 36 | list_of_pixels_of_y.append(pixels[pixel_coordinate_of_x+1,pixel_coordinate_of_y][0]) 37 | 38 | #plotting of values to a graph 39 | plt.scatter(list_of_pixels_of_x,list_of_pixels_of_y, label='Pixel',color='k',s=2,edgecolors='r') 40 | plt.xlabel('Pixel value on location(x,y)') 41 | plt.ylabel('Pixel value on location(x+1,y)') 42 | plt.title("correlation coefficient graph") 43 | plt.legend() 44 | plt.savefig(output+"/coplot_horizontal.png") 45 | 46 | #plt.savefig("fog.png") 47 | 48 | 49 | def coplot_vertical(loc): 50 | image = Image.open(loc) 51 | pixels = image.load() 52 | list_of_pixels_of_x = [] 53 | list_of_pixels_of_y = [] 54 | 55 | width, height = image.size 56 | 57 | #running for loop to traverse all the pixel values of the image 58 | for pixel_coordinate_of_y in range(0, 50): 59 | for pixel_coordinate_of_x in range(0, 50): 60 | 61 | # adding pixel value to a list 62 | list_of_pixels_of_x.append(pixels[pixel_coordinate_of_y,pixel_coordinate_of_x][0]) 63 | if pixel_coordinate_of_y + 1 == height: 64 | list_of_pixels_of_y.pop() 65 | break 66 | else: 67 | 68 | # adding pixel value to a list 69 | list_of_pixels_of_y.append(pixels[pixel_coordinate_of_y , pixel_coordinate_of_x+1][0]) 70 | 71 | #plotting of values to a graph 72 | plt.scatter(list_of_pixels_of_x, list_of_pixels_of_y, label='Pixel', color='k', s=2, edgecolors='r') 73 | plt.xlabel('Pixel value on location(x,y)') 74 | plt.ylabel('Pixel value on location(x+1,y)') 75 | plt.title("correlation coefficient graph") 76 | plt.legend() 77 | plt.show() -------------------------------------------------------------------------------- /correlationcofficient.py: -------------------------------------------------------------------------------- 1 | """ 2 | This module two libraries pillow as PIL and math lib.This module is based on a mathematical formula called 3 | pearson's correlation coefficient.It calculates the relation between two adjacent pixel values.Each component of the 4 | formula is divided into four parts which are co1,co2,co3,co4. 5 | 6 | It has a module named corr_of_rgb().It calculates correlation of all r,g,b and returns the average correlation 7 | of the image.This module can be called bu passing te location of the whose correlation coefficient is to be calculated. 8 | for example-: corr_of_rgb(loc) 9 | """ 10 | 11 | from PIL import Image 12 | from math import sqrt 13 | 14 | value_of_x=0 15 | value_of_y=0 16 | 17 | #color_index_of_rgb 0-red,1-green,2-blue 18 | def co1(color_index_of_rgb,height,width,pixels): 19 | value=0 20 | for pixel_coordinate_of_y in range(0, height): 21 | for pixel_coordinate_of_x in range(0, width): 22 | if pixel_coordinate_of_x+1==width: 23 | break 24 | value=pixels[pixel_coordinate_of_x,pixel_coordinate_of_y][color_index_of_rgb]*pixels[pixel_coordinate_of_x+1,pixel_coordinate_of_y][color_index_of_rgb]+value 25 | 26 | 27 | return value*height*width 28 | 29 | def co2(color_index_of_rgb,height,width,pixels): 30 | global value_of_y 31 | global value_of_x 32 | for pixel_coordinate_of_y in range(0, height): 33 | for pixel_coordinate_of_x in range(0, width): 34 | if pixel_coordinate_of_x+1==width: 35 | break 36 | value_of_x=pixels[pixel_coordinate_of_x,pixel_coordinate_of_y][color_index_of_rgb]+value_of_x 37 | value_of_y=pixels[pixel_coordinate_of_x+1,pixel_coordinate_of_y][color_index_of_rgb]+value_of_y 38 | 39 | return value_of_x*value_of_y 40 | 41 | 42 | def co3(color_index_of_rgb,height,width,pixels): 43 | value=0 44 | for pixel_coordinate_of_y in range(0, height): 45 | for pixel_coordinate_of_x in range(0, width): 46 | value=(pixels[pixel_coordinate_of_x,pixel_coordinate_of_y][color_index_of_rgb])**2 +value 47 | 48 | xy=(value*height*width)-(value_of_x**2) 49 | return xy 50 | 51 | def co4(color_index_of_rgb,height,width,pixels): 52 | value=0 53 | for pixel_coordinate_of_y in range(0, height): 54 | for pixel_coordinate_of_x in range(0, width): 55 | if pixel_coordinate_of_x+1==width: 56 | break 57 | value=(pixels[pixel_coordinate_of_x+1,pixel_coordinate_of_y][color_index_of_rgb]**2)+value 58 | 59 | xy=(value*height*width)-(value_of_y**2) 60 | return xy 61 | 62 | def corr_of_rgb(loc): 63 | global value_of_y 64 | global value_of_x 65 | photo = Image.open(loc) 66 | # cryptotiger.bmp 67 | pixels = photo.load() 68 | width, height = photo.size 69 | value_of_y = 0 70 | value_of_x = 0 71 | r=((co1(0,height,width,pixels)-co2(0,height,width,pixels)) / sqrt(co3(0,height,width,pixels)*co4(0,height,width,pixels))) 72 | value_of_y=0 73 | value_of_x=0 74 | g=((co1(1,height,width,pixels) - co2(1,height,width,pixels)) / sqrt(co3(1,height,width,pixels) * co4(1,height,width,pixels))) 75 | value_of_x=0 76 | value_of_y=0 77 | b=((co1(2,height,width,pixels) - co2(2,height,width,pixels)) / sqrt(co3(2,height,width,pixels) * co4(2,height,width,pixels))) 78 | 79 | return ((r+g+b)/3) 80 | #cr=(co1()-co2()) / sqrt(co3()*co4()) 81 | 82 | #print(cr) 83 | 84 | #corr_of_rgb("abc.png") 85 | -------------------------------------------------------------------------------- /cryptotiger.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/knowankit/Image-encryption-using-chaos-theory/0e91d635e2b6161f8f8d6ef285bed030c071e556/cryptotiger.bmp -------------------------------------------------------------------------------- /gui.py: -------------------------------------------------------------------------------- 1 | """ 2 | This is a desktop based GUI application. Libraries like tkinter,PIL have been used to make it.A user can encrypt or decrypt the image file 3 | from this gui.It have to modules encrypt and decrypt.This gui used grid layout which means size will remains same in every window. 4 | """ 5 | from tkinter import * 6 | #Imported from chaos package 7 | from Chaos.Encryption import encrypt 8 | from Chaos.Decryption import decrypt 9 | 10 | from tkinter import filedialog #GUI library 11 | from PIL import ImageTk, Image #image manipulation library 12 | 13 | from os.path import getsize 14 | 15 | import os 16 | 17 | root = Tk() #Initialising the window frame 18 | root.geometry("600x550") #Size of the window 19 | root.configure(background="#26292c") #background colorr of the window 20 | root.title("Chaos Based Image Encryption") 21 | #title on the title bar of the window 22 | curr=os.getcwd() 23 | 24 | 25 | #Function to choose a file from the system directory 26 | def askopenfile(): 27 | path = filedialog.askopenfilename(filetypes=[("Image File", '.jpg'),("Image File",'.png')]) #allowed image formats are .jpg and .png 28 | input_file_entry.delete(0,'end') #Delete the address value present in the address bar 29 | im = Image.open(path) #Opening image with the previous fetched path 30 | input_file_entry.insert(END, path) # inserting the file location in the address bar 31 | im = im.resize((200, 200), Image.ANTIALIAS) #resizing the fetched image 32 | tkimage = ImageTk.PhotoImage(im) #defining the format of the image 33 | print(getsize(path)) 34 | myvar = Label(root, image=tkimage) #Displaying the image on the window with the help of label object 35 | 36 | myvar.image = tkimage #assigning the image value 37 | 38 | myvar.grid(row=1, column=0) #Placing the image using grid layout 39 | """ 40 | Encrypt function has two parameters which are image object and secret key of 80 bits.Doencrypt is used to call the encrypt function. 41 | """ 42 | def doencrypt(): 43 | loc=input_file_entry.get() #Fecthing the location of the file to be encrypted 44 | key=password_entry.get() #Fetching the key value 45 | encrypted_image=encrypt(loc,key) #Encrypting the image by calling encrypt method which returns the encrypted image 46 | encrypted_image.save("abc" + ".png") #Saving the encrypted image as .png 47 | im = Image.open("abc.png") #Opening the encryppted image 48 | im = im.resize((200, 200), Image.ANTIALIAS) #Resizing the encrypted image 49 | tkimage = ImageTk.PhotoImage(im) #Defining the image value 50 | myvar = Label(root, image=tkimage) #Displaying the with the help of label object 51 | myvar.image = tkimage # Assigning the image attribute 52 | myvar.grid(row=1, column=1) #Placing the image using grid layout 53 | 54 | 55 | """ 56 | Decrypt function has two parameters which are image object and secret key of 80 bits.Dodecrypt is used to call the decrypt function. 57 | """ 58 | def dodecrypt(): 59 | loc="abc.png" #Location of decrypted iamge 60 | decrypted_image=decrypt(loc,password_entry.get()) #Calling decrypt function tod ecrypt the image by passing encryptd image with the key 61 | decrypted_image.save("dabc"+".png") #saving decrypted image as .png 62 | im=Image.open("dabc.png") #Opening decrypted image 63 | im = im.resize((200, 200), Image.ANTIALIAS) #Resizing decrypted image 64 | tkimage = ImageTk.PhotoImage(im) #Loading image as an Object 65 | myvar = Label(root, image=tkimage) #Displaying image with the help of Label Object 66 | myvar.image = tkimage #assigning image value 67 | myvar.grid(row=1, column=1) #Placing image using grid layout in the window 68 | 69 | loc="abc.png" 70 | dloc="dabc.png" 71 | browse_input_file=Button(root,text="Select Image",command=askopenfile,width=15,height=2,bg="#657cc3") #Browse Button 72 | input_file_entry=Entry(root,width=28) #Address Label 73 | 74 | password=Label(root,text="Enter Key",width=18,height=1,bg="#657cc3") #Password Label 75 | password_entry=Entry(root,width=20) #Password entry box 76 | 77 | encryptb=Button(root, text="Encrypt Image", width=18, height=2,command=doencrypt,bg="#37b448" ) #Placing the object using grid layout 78 | decryptb=Button(root,text="Decrypt Image",width=18,height=2,command=dodecrypt,bg="#37b448") #Placing the object using grid layout 79 | 80 | 81 | encryptb.grid(row=4,columnspan=5,pady=10)#Placing the object using grid layout 82 | decryptb.grid(row=5,columnspan=5,pady=15)#Placing the object using grid layout 83 | password.grid(row=2,columnspan=5,pady=10)#Placing the object using grid layout 84 | password_entry.grid(row=3,columnspan=5)#Placing the object using grid layout 85 | browse_input_file.grid(row=0,padx=80,pady=50)#Placing the object using grid layout 86 | input_file_entry.grid(row=0,column=1,padx=50)#Placing the object using grid layout 87 | 88 | root.mainloop() #Closing the Frame 89 | -------------------------------------------------------------------------------- /histogram.py: -------------------------------------------------------------------------------- 1 | """ 2 | This module consist of three module redhistogram,bluehistogram,greenhitogram.All these modules does the histogram analysis of the 3 | red , blue and green color present in the images.For calculating the histogram of different color ,pillow image library 4 | is used .And to plot the data on graph matplotlib library has been used. 5 | """ 6 | 7 | from PIL import Image 8 | from pylab import * 9 | import matplotlib.pylab as plt 10 | import matplotlib.pylab as plt2 11 | 12 | 13 | def rgbhistogram(loc,output): 14 | 15 | im = array(Image.open(loc).convert('RGB')) 16 | 17 | im2 = 255 - im # invert image green 18 | im3 = (100.0 / 255) * im + 100 # clamp to interval 100...200 red 19 | im4 = 255.0 * (im / 255.0) ** 2 # squared blue 20 | plt2.axis('equal') 21 | plt2.axis('off') 22 | plt2.figure() 23 | plt2.hist(im2.flatten(), 128) 24 | plt2.hist(im3.flatten(), 128) 25 | plt2.hist(im4.flatten(), 128) 26 | plt2.savefig(output+"/rgbhisto.png") 27 | 28 | 29 | def rgbhistogram2(loc,output): 30 | im = array(Image.open(loc).convert('RGB')) 31 | 32 | im2 = 255 - im # invert image green 33 | im3 = (100.0 / 255) * im + 100 # clamp to interval 100...200 red 34 | im4 = 255.0 * (im / 255.0) ** 2 # squared blue 35 | plt2.axis('equal') 36 | plt2.axis('on') 37 | plt2.figure() 38 | plt2.hist(im2.flatten(), 128) 39 | plt2.hist(im3.flatten(), 128) 40 | plt2.hist(im4.flatten(), 128) 41 | plt2.savefig(output+"/rgbhisto2.png") 42 | 43 | 44 | def redhistogram(loc): 45 | im = array(Image.open(loc).convert('RGB')) #Opening the image 46 | im = (100.0 / 255) * im + 100 # clamp to interval 100...200 red 47 | #Fecthing red pixels 48 | axis('equal') 49 | axis('off') 50 | figure() 51 | hist(im.flatten(), 128) #Designing the histogram 52 | 53 | show() 54 | 55 | 56 | def greenhistogram(loc): 57 | im = array(Image.open(loc).convert('RGB')) #Opening the image 58 | im = 255 - im # invert image green #Fecthing green pixels 59 | axis('equal') 60 | axis('off') 61 | figure() 62 | hist(im.flatten(), 128)#Designing the histogram 63 | show() 64 | 65 | 66 | def bluehistogram(loc): 67 | im = array(Image.open(loc).convert('RGB')) #Opening the image 68 | im = 255.0 * (im / 255.0) ** 2 # squared blue #Fecthing blue pixels 69 | axis('equal') 70 | axis('off') 71 | figure() 72 | hist(im.flatten(), 128)#Designing the histogram 73 | show() 74 | 75 | 76 | # im = array(Image.open('abc.png').convert('RGB')) 77 | # 78 | # im2 = 255 - im # invert image green 79 | # 80 | # im3 = (100.0/255) * im + 100 # clamp to interval 100...200 red 81 | # 82 | # im4 = 255.0 * (im/255.0)**2 # squared blue 83 | # # create a new figure 84 | # figure() 85 | # # don't use colors 86 | # #gray() 87 | # # show contours with origin upper left corner 88 | # #contour(im2, origin='image') 89 | # 90 | # axis('equal') 91 | # axis('off') 92 | # figure() 93 | # hist(im2.flatten(),128) 94 | # # hist(im3.flatten(),128) 95 | # # hist(im.flatten(),128) 96 | # # hist(im4.flatten(),128) 97 | # # # 98 | # show() -------------------------------------------------------------------------------- /meansquareerror.py: -------------------------------------------------------------------------------- 1 | """ 2 | It calculates the difference between two images.This is just thee coding of a mathematical formula. 3 | This function can called by passing two image object as parameters and then decimal value will be returned. 4 | """ 5 | from PIL import ImageChops,Image 6 | import math, operator 7 | 8 | def rootmeansquare(im1, im2): 9 | "Calculate the root-mean-square difference between two images" 10 | diff = ImageChops.difference(im1, im2) 11 | h = diff.histogram() 12 | sq = (value*(idx**2) for idx, value in enumerate(h)) 13 | sum_of_squares = sum(sq) 14 | rms = math.sqrt(sum_of_squares/float(im1.size[0] * im1.size[1])) 15 | return rms 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /npcr.py: -------------------------------------------------------------------------------- 1 | """ 2 | It has a NPCR(Number of pixel changed rate).It compares the pixel values of the original image and the encrypted image. 3 | The resultant value is returned in percentage.If the value is more than 99% then the analysis is positive. 4 | 5 | It consist of three modules rateofchange(),sumofpixel(),npcrv(). 6 | """ 7 | 8 | 9 | 10 | from PIL import Image 11 | import numpy as np 12 | 13 | """ 14 | This method compares two image.If the pixel value is same then 0 is stored in the matrix else one is stored 15 | """ 16 | def rateofchange(height,width,pixel1,pixel2,matrix,i): 17 | 18 | for y in range(0,height): 19 | for x in range(0,width): 20 | #print(x,y) 21 | if pixel1[x,y][i] == pixel2[x,y][i]: 22 | matrix[x,y]=0 23 | else: 24 | matrix[x,y]=1 25 | return matrix 26 | """ 27 | sum of the values of 1 stored in matrix is calculated 28 | """ 29 | def sumofpixel(height,width,pixel1,pixel2,ematrix,i): 30 | matrix=rateofchange(height,width,pixel1,pixel2,ematrix,i) 31 | psum=0 32 | for y in range(0,height): 33 | for x in range(0,width): 34 | psum=matrix[x,y]+psum 35 | return psum 36 | 37 | """ 38 | Finally the above two module is called to calculate the values 39 | """ 40 | def npcrv(loc1,loc2): 41 | c1 = Image.open(loc1) 42 | c2 = Image.open(loc2) 43 | width, height = c1.size 44 | pixel1 = c1.load() 45 | pixel2 = c2.load() 46 | ematrix = np.empty([width, height]) 47 | per=(((sumofpixel(height,width,pixel1,pixel2,ematrix,0)/(height*width))*100)+((sumofpixel(height,width,pixel1,pixel2,ematrix,1)/(height*width))*100)+((sumofpixel(height,width,pixel1,pixel2,ematrix,2)/(height*width))*100))/3 48 | return per 49 | 50 | #print(npcrv("encrypted116.png","encrypted16.png")) 51 | 52 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## Image Encryption using Chaos theory 2 | 3 | This project deals with the encryption and decryption of the image using two logistic equation which is iterated in a loop at a certain number of times to genearte distinct value.The generated distinct value is used in key generatioan where it is further used in operations like XORing with the pixels. 4 | 5 | A separate Image analyzer tool is provided to do avarious kinds of analysis on the image. 6 | Analysis like NPCR(Number Of Pixels Changed Rate),UACI(Unified Average Changed Intensity),Correlation coefficient ,RMSE(Root Mean Square Error) ,Histogram are integrated in this 7 | software . 8 | 9 | ### Prerequisites 10 | * If you want to modify the code then you need to install any IDE for python like PyCharm (optional) 11 | * This codes works on both python 2.7 and 3.2 version 12 | 13 | ### Installing 14 | Copy this project folder into your project workspace. Open the GUI.py file in the IDE 15 | You will get some errors as many libraries will be unavailable. Libraries required to 16 | run this code are matplotlib, pillow, numbpy, histogram, tkinter 17 | 18 | ### Built With 19 | * ###### Pycharm IDE 20 | * ###### matplotlib 21 | * ###### numpy 22 | * ###### Tkinter library 23 | * ###### pillow 24 | 25 | 26 | ### Author 27 | * ###### [Ankit Kumar](http://github.com/knowankit) 28 | * ###### Aditya Prakash 29 | * ###### [Ghulam Khan](http://github.com/waynetech) 30 | 31 | ### License 32 | This project is free to use and modify 33 | 34 | 35 | ### Notes: 36 | * Allowed image formats are .jpeg and .png. User can select any of the mentioned image format. 37 | 38 | * User can use their own secret key to encrypt and decrypt the image. 39 | 40 | * Encryption and decryption time of the image depends on the size and resolution of the image. 41 | 42 | * This project also analyzes the encrypted and original images. 43 | 44 | ### Modules of this project- 45 | 46 | 1. Chaos Module 47 | 2. Image analyzer tool 48 | 3. Web application 49 | 4. Desktop application 50 | 51 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pillow 2 | numpy 3 | matplotlib 4 | 5 | -------------------------------------------------------------------------------- /tiger.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/knowankit/Image-encryption-using-chaos-theory/0e91d635e2b6161f8f8d6ef285bed030c071e556/tiger.bmp -------------------------------------------------------------------------------- /uaci.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | import math 3 | # Sama as NPCR both are used for sensitivity analysis two encrypted image is required 4 | 5 | """ 6 | Unified average avereage inensity changed rate 7 | 8 | this code calculates average intensity change rate of pixels 9 | """ 10 | def uaci(loc1,loc2): 11 | image1 = Image.open(loc1) 12 | image2 = Image.open(loc2) 13 | pixel1=image1.load() 14 | pixel2=image2.load() 15 | width,height=image1.size 16 | value=0.0 17 | for y in range(0,height): 18 | for x in range(0,width): 19 | value=(abs(pixel1[x,y][0]-pixel2[x,y][0])/255)+value 20 | 21 | value=(value/(width*height))*100 22 | return value 23 | 24 | #print(uaci("encrypted16.png","encrypted116.png")) 25 | 26 | #decrypted image and original image 27 | 28 | """ 29 | It contains a module named rootmeansquareerror().It checks the difference occured in the pixels between the original_image 30 | and the decrypted_image.If all pixels are same then this will return 0. 31 | 32 | rootmeansquareerror() can be called by passing two image location as parameters .one will be original image and the other will be 33 | decrypted image.This uses two libraries pillow for image manipulation and math library 34 | """ 35 | def rootmeansquareerror(loc1,loc2): 36 | image1 = Image.open(loc1) 37 | image2 = Image.open(loc2) 38 | pixel1 = image1.load() 39 | pixel2 = image2.load() 40 | width, height = image1.size 41 | value1 = 0.0 42 | value2=0.0 43 | value3=0.0 44 | 45 | #comparing of pixel values between two images 46 | for y in range(0,height): 47 | for x in range(0,width): 48 | value1=((pixel1[x,y][0]-pixel2[x,y][0])**2)+value1 49 | value2 = ((pixel1[x, y][1] - pixel2[x, y][1]) ** 2) + value2 50 | value3 = ((pixel1[x, y][2] - pixel2[x, y][2]) ** 2) + value3 51 | value1=value1/(height*width) 52 | 53 | return (value1+value2+value3)/3 54 | 55 | # def psnr(rmse): 56 | # value=(math.log10(255)*20)-(math.log10(rmse)*10) 57 | # return value 58 | # 59 | --------------------------------------------------------------------------------