├── .gitignore ├── Image ├── encryption │ ├── encrypted_image.jpg │ └── permutated_image.jpg ├── example_encryption_decryption_image.png ├── keyspace_sensitivity │ ├── diff_1.jpg │ ├── diff_2.jpg │ ├── diff_perm_1.jpg │ ├── diff_perm_2.jpg │ ├── difference_diff.jpg │ ├── difference_diff_perm.jpg │ ├── difference_perm.jpg │ ├── difference_perm_diff.jpg │ ├── perm_1.jpg │ ├── perm_2.jpg │ ├── perm_diff_1.jpg │ └── perm_diff_2.jpg ├── sample_image_grey.jpg └── sample_image_rgb.jpg ├── LICENSE ├── README.md ├── decryption.cpp ├── encryption.cpp ├── encryption ├── decryption.cpp ├── encryption └── encryption.cpp ├── key_sensivity ├── key_sensivity.cpp └── keyspace_sensitivity ├── difference_perm_diff.jpg ├── diffusion ├── diffusion.cpp ├── diffusion_permutation ├── diffusion_permutation.cpp ├── perm_diff_1.jpg ├── permutation ├── permutation.cpp ├── permutation_diffusion ├── permutation_diffusion.cpp ├── test └── test.cpp /.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeShaurya/Image-encryption/b5a3139da21c0effff34cfb09744cfe2d845d486/.gitignore -------------------------------------------------------------------------------- /Image/encryption/encrypted_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeShaurya/Image-encryption/b5a3139da21c0effff34cfb09744cfe2d845d486/Image/encryption/encrypted_image.jpg -------------------------------------------------------------------------------- /Image/encryption/permutated_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeShaurya/Image-encryption/b5a3139da21c0effff34cfb09744cfe2d845d486/Image/encryption/permutated_image.jpg -------------------------------------------------------------------------------- /Image/example_encryption_decryption_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeShaurya/Image-encryption/b5a3139da21c0effff34cfb09744cfe2d845d486/Image/example_encryption_decryption_image.png -------------------------------------------------------------------------------- /Image/keyspace_sensitivity/diff_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeShaurya/Image-encryption/b5a3139da21c0effff34cfb09744cfe2d845d486/Image/keyspace_sensitivity/diff_1.jpg -------------------------------------------------------------------------------- /Image/keyspace_sensitivity/diff_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeShaurya/Image-encryption/b5a3139da21c0effff34cfb09744cfe2d845d486/Image/keyspace_sensitivity/diff_2.jpg -------------------------------------------------------------------------------- /Image/keyspace_sensitivity/diff_perm_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeShaurya/Image-encryption/b5a3139da21c0effff34cfb09744cfe2d845d486/Image/keyspace_sensitivity/diff_perm_1.jpg -------------------------------------------------------------------------------- /Image/keyspace_sensitivity/diff_perm_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeShaurya/Image-encryption/b5a3139da21c0effff34cfb09744cfe2d845d486/Image/keyspace_sensitivity/diff_perm_2.jpg -------------------------------------------------------------------------------- /Image/keyspace_sensitivity/difference_diff.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeShaurya/Image-encryption/b5a3139da21c0effff34cfb09744cfe2d845d486/Image/keyspace_sensitivity/difference_diff.jpg -------------------------------------------------------------------------------- /Image/keyspace_sensitivity/difference_diff_perm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeShaurya/Image-encryption/b5a3139da21c0effff34cfb09744cfe2d845d486/Image/keyspace_sensitivity/difference_diff_perm.jpg -------------------------------------------------------------------------------- /Image/keyspace_sensitivity/difference_perm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeShaurya/Image-encryption/b5a3139da21c0effff34cfb09744cfe2d845d486/Image/keyspace_sensitivity/difference_perm.jpg -------------------------------------------------------------------------------- /Image/keyspace_sensitivity/difference_perm_diff.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeShaurya/Image-encryption/b5a3139da21c0effff34cfb09744cfe2d845d486/Image/keyspace_sensitivity/difference_perm_diff.jpg -------------------------------------------------------------------------------- /Image/keyspace_sensitivity/perm_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeShaurya/Image-encryption/b5a3139da21c0effff34cfb09744cfe2d845d486/Image/keyspace_sensitivity/perm_1.jpg -------------------------------------------------------------------------------- /Image/keyspace_sensitivity/perm_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeShaurya/Image-encryption/b5a3139da21c0effff34cfb09744cfe2d845d486/Image/keyspace_sensitivity/perm_2.jpg -------------------------------------------------------------------------------- /Image/keyspace_sensitivity/perm_diff_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeShaurya/Image-encryption/b5a3139da21c0effff34cfb09744cfe2d845d486/Image/keyspace_sensitivity/perm_diff_1.jpg -------------------------------------------------------------------------------- /Image/keyspace_sensitivity/perm_diff_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeShaurya/Image-encryption/b5a3139da21c0effff34cfb09744cfe2d845d486/Image/keyspace_sensitivity/perm_diff_2.jpg -------------------------------------------------------------------------------- /Image/sample_image_grey.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeShaurya/Image-encryption/b5a3139da21c0effff34cfb09744cfe2d845d486/Image/sample_image_grey.jpg -------------------------------------------------------------------------------- /Image/sample_image_rgb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeShaurya/Image-encryption/b5a3139da21c0effff34cfb09744cfe2d845d486/Image/sample_image_rgb.jpg -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Shubham Maurya 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Image Encryption technique based on chaotic maps 2 | Evaluating the permutation and diffusion operations used in image encryption based on chaotic maps 3 | 4 | 5 | # To compile program:- 6 | 7 | **$g++ -o `${compiled_file}` `${file_name}` 'pkg-config opencv --cflags --libs'** 8 | 9 | eg. 10 | 11 | **$g++ -o encryption encryption.cpp 'pkg-config opencv --cflags --libs'** 12 | 13 | # To Execute generated binary file:- 14 | 15 | **$ ./encryption** 16 | 17 | 18 | # 19 | 20 | 21 | In this project a Research Paper is used. [Evaluating the permutation and diffusion operations used in image encryption based on chaotic maps](https://ac.els-cdn.com/S0030402616000279/1-s2.0-S0030402616000279-main.pdf?_tid=8c235cf4-a7bc-41fe-b6bb-e77d9df1f893&acdnat=1537901559_94c0591f3ff0ae3108215529fcabc75d) 22 | 23 | **prerequisites:** 24 | * Basic operations on images 25 | * Basic knowledge of OpenCV with C++ 26 | 27 | Here OpenCv with c++ is not mandatory work environment. You can also choose Matlab or openCv with any language. Main part of this implementation is the algorithm. 28 | 29 | # Execution example: 30 | 31 | ![alt text](Image/example_encryption_decryption_image.png) 32 | -------------------------------------------------------------------------------- /decryption.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace cv; 5 | using namespace std; 6 | 7 | const int MAX=1e4+79; 8 | 9 | /** 10 | u is the control parameter for logistic chaotic map,also known as population rate 11 | Here u is taken 3.94 12 | 13 | x is the vector that contain the value generated by chaotic map 14 | The initial value of the logistic chaotic map is 0.4 15 | */ 16 | 17 | int main() 18 | { 19 | Mat image; 20 | int i,l; 21 | double u=3.94; 22 | vector> x; 23 | Vec pixel; 24 | 25 | image = imread("Image/encrypted_image.jpg", 0 ); 26 | if ( !image.data ) 27 | { 28 | cout<<"No image data \n"; 29 | return -1; 30 | } 31 | 32 | x.push_back({0.4,0}); 33 | 34 | 35 | double temp; 36 | for (int i = 1; i <= 511; ++i){ 37 | temp=u*x[i-1].first*(1-x[i-1].first); 38 | x.push_back({temp,i}); 39 | } 40 | 41 | sort(x.begin(), x.end()); 42 | 43 | imshow("Decrepted image", image); 44 | waitKey(0); 45 | 46 | i=1; 47 | for(int r = 0; r < image.rows; ++r) { 48 | for(int c = 0; c < image.cols; ++c) { 49 | if(i>100){ 50 | i=1; 51 | } 52 | l=x[i].first*MAX; 53 | l=l%255; 54 | image.at(r,c)[0]=image.at(r,c)[0]^l; 55 | image.at(r,c)[1]=image.at(r,c)[1]^l; 56 | image.at(r,c)[2]=image.at(r,c)[2]^l; 57 | i++; 58 | } 59 | } 60 | 61 | i=511; 62 | for(int r = image.rows-1; r >= 0; --r) { 63 | for(int c = image.cols-1; c >= 0 ; --c) { 64 | if(i<0) 65 | i=511; 66 | int temps= x[i].second; 67 | 68 | pixel= image.at(r,temps); 69 | image.at(r,temps)=image.at(r,c); 70 | image.at(r,c)=pixel; 71 | 72 | i--; 73 | } 74 | } 75 | 76 | namedWindow("Original_image", WINDOW_AUTOSIZE ); 77 | imshow("Original_image", image); 78 | waitKey(0); 79 | 80 | return 0; 81 | 82 | } -------------------------------------------------------------------------------- /encryption.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace cv; 5 | using namespace std; 6 | 7 | const int MAX=1e4+79; 8 | 9 | /** 10 | u is the control parameter for logistic chaotic map,also known as population rate 11 | Here u is taken 3.94 12 | x is the vector that contain the value generated by chaotic map 13 | The initial value of the logistic chaotic map is 0.4 14 | */ 15 | 16 | int main() 17 | { 18 | Mat image; 19 | int i,l; 20 | double u=3.94; 21 | vector> x; 22 | Vec pixel; 23 | 24 | image = imread("Image/sample_image_grey.jpg", 0 ); 25 | if ( !image.data ) 26 | { 27 | cout<<"No image data \n"; 28 | return -1; 29 | } 30 | 31 | x.push_back({0.4,0}); 32 | 33 | 34 | double temp; 35 | for (int i = 1; i <= 511; ++i){ 36 | temp=u*x[i-1].first*(1-x[i-1].first); 37 | x.push_back({temp,i}); 38 | } 39 | 40 | sort(x.begin(), x.end()); 41 | 42 | imshow("Original image", image); 43 | waitKey(0); 44 | 45 | i=0; 46 | for(int r = 0; r < image.rows; ++r) { 47 | for(int c = 0; c < image.cols; ++c) { 48 | if(i>511) 49 | i=0; 50 | int temps= x[i].second; 51 | 52 | pixel= image.at(r,temps); 53 | image.at(r,temps)=image.at(r,c); 54 | image.at(r,c)=pixel; 55 | 56 | i++; 57 | } 58 | } 59 | 60 | imshow("permutated image", image); 61 | waitKey(0); 62 | 63 | for(int r = 0; r < image.rows; ++r) { 64 | for(int c = 0; c < image.cols; ++c) { 65 | if(i>100){ 66 | i=1; 67 | } 68 | l=x[i].first*MAX; 69 | l=l%255; 70 | image.at(r,c)[0]=image.at(r,c)[0]^l; 71 | image.at(r,c)[1]=image.at(r,c)[1]^l; 72 | image.at(r,c)[2]=image.at(r,c)[2]^l; 73 | i++; 74 | } 75 | } 76 | 77 | imwrite("Image/encrypted_image.jpg",image); 78 | imshow("Encrypted image", image); 79 | waitKey(0); 80 | 81 | i=1; 82 | for(int r = 0; r < image.rows; ++r) { 83 | for(int c = 0; c < image.cols; ++c) { 84 | if(i>100){ 85 | i=1; 86 | } 87 | l=x[i].first*MAX; 88 | l=l%255; 89 | image.at(r,c)[0]=image.at(r,c)[0]^l; 90 | image.at(r,c)[1]=image.at(r,c)[1]^l; 91 | image.at(r,c)[2]=image.at(r,c)[2]^l; 92 | i++; 93 | } 94 | } 95 | 96 | imshow("Decrepted Diffused image", image); 97 | waitKey(0); 98 | 99 | i=511; 100 | for(int r = image.rows-1; r >= 0; --r) { 101 | for(int c = image.cols-1; c >= 0 ; --c) { 102 | if(i<0) 103 | i=511; 104 | int temps= x[i].second; 105 | 106 | pixel= image.at(r,temps); 107 | image.at(r,temps)=image.at(r,c); 108 | image.at(r,c)=pixel; 109 | 110 | i--; 111 | } 112 | } 113 | 114 | namedWindow("Decrepted", WINDOW_AUTOSIZE ); 115 | imshow("Decrepted", image); 116 | waitKey(0); 117 | 118 | return 0; 119 | 120 | } -------------------------------------------------------------------------------- /encryption/decryption.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace cv; 5 | using namespace std; 6 | 7 | const int MAX=1e4+79; 8 | 9 | /** 10 | u is the control parameter for logistic chaotic map,also known as population rate 11 | Here u is taken 3.94 12 | 13 | x is the vector that contain the value generated by chaotic map 14 | The initial value of the logistic chaotic map is 0.4 15 | */ 16 | 17 | int main() 18 | { 19 | Mat image; 20 | int i,l; 21 | double u=3.94; 22 | vector> x; 23 | Vec pixel; 24 | 25 | image = imread("Image/encryption/encrypted_image.jpg", 0 ); 26 | if ( !image.data ) 27 | { 28 | cout<<"No image data \n"; 29 | return -1; 30 | } 31 | 32 | x.push_back({0.4,0}); 33 | 34 | 35 | double temp; 36 | for (int i = 1; i <= 511; ++i){ 37 | temp=u*x[i-1].first*(1-x[i-1].first); 38 | x.push_back({temp,i}); 39 | } 40 | 41 | sort(x.begin(), x.end()); 42 | 43 | imshow("Decrypted image", image); 44 | waitKey(0); 45 | 46 | i=1; 47 | for(int r = 0; r < image.rows; ++r) { 48 | for(int c = 0; c < image.cols; ++c) { 49 | if(i>100){ 50 | i=1; 51 | } 52 | l=x[i].first*MAX; 53 | l=l%255; 54 | image.at(r,c)[0]=image.at(r,c)[0]^l; 55 | image.at(r,c)[1]=image.at(r,c)[1]^l; 56 | image.at(r,c)[2]=image.at(r,c)[2]^l; 57 | i++; 58 | } 59 | } 60 | 61 | i=511; 62 | for(int r = image.rows-1; r >= 0; --r) { 63 | for(int c = image.cols-1; c >= 0 ; --c) { 64 | if(i<0) 65 | i=511; 66 | int temps= x[i].second; 67 | 68 | pixel= image.at(r,temps); 69 | image.at(r,temps)=image.at(r,c); 70 | image.at(r,c)=pixel; 71 | 72 | i--; 73 | } 74 | } 75 | 76 | namedWindow("Original_image", WINDOW_AUTOSIZE ); 77 | imshow("Original_image", image); 78 | waitKey(0); 79 | 80 | return 0; 81 | 82 | } -------------------------------------------------------------------------------- /encryption/encryption: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeShaurya/Image-encryption/b5a3139da21c0effff34cfb09744cfe2d845d486/encryption/encryption -------------------------------------------------------------------------------- /encryption/encryption.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace cv; 5 | using namespace std; 6 | 7 | const int MAX=1e4+79; 8 | 9 | /** 10 | u is the control parameter for logistic chaotic map,also known as population rate 11 | Here u is taken 3.94 12 | x is the vector that contain the value generated by chaotic map 13 | The initial value of the logistic chaotic map is 0.4 14 | */ 15 | 16 | int main() 17 | { 18 | Mat image; 19 | int i,l; 20 | double u=3.94; 21 | vector> x; 22 | Vec pixel; 23 | 24 | image = imread("Image/sample_image_grey.jpg", 0 ); 25 | if ( !image.data ) 26 | { 27 | cout<<"No image data \n"; 28 | return -1; 29 | } 30 | 31 | x.push_back({0.4,0}); 32 | 33 | 34 | double temp; 35 | for (int i = 1; i <= 511; ++i){ 36 | temp=u*x[i-1].first*(1-x[i-1].first); 37 | x.push_back({temp,i}); 38 | } 39 | 40 | sort(x.begin(), x.end()); 41 | 42 | imshow("Original image", image); 43 | waitKey(0); 44 | 45 | i=0; 46 | for(int r = 0; r < image.rows; ++r) { 47 | for(int c = 0; c < image.cols; ++c) { 48 | if(i>511) 49 | i=0; 50 | int temps= x[i].second; 51 | 52 | pixel= image.at(r,temps); 53 | image.at(r,temps)=image.at(r,c); 54 | image.at(r,c)=pixel; 55 | 56 | i++; 57 | } 58 | } 59 | 60 | imwrite("Image/encryption/permutated_image.jpg",image); 61 | imshow("permutated image", image); 62 | waitKey(0); 63 | 64 | for(int r = 0; r < image.rows; ++r) { 65 | for(int c = 0; c < image.cols; ++c) { 66 | if(i>100){ 67 | i=1; 68 | } 69 | l=x[i].first*MAX; 70 | l=l%255; 71 | image.at(r,c)[0]=image.at(r,c)[0]^l; 72 | image.at(r,c)[1]=image.at(r,c)[1]^l; 73 | image.at(r,c)[2]=image.at(r,c)[2]^l; 74 | i++; 75 | } 76 | } 77 | 78 | imwrite("Image/encryption/encrypted_image.jpg",image); 79 | imshow("Encrypted image", image); 80 | waitKey(0); 81 | 82 | i=1; 83 | for(int r = 0; r < image.rows; ++r) { 84 | for(int c = 0; c < image.cols; ++c) { 85 | if(i>100){ 86 | i=1; 87 | } 88 | l=x[i].first*MAX; 89 | l=l%255; 90 | image.at(r,c)[0]=image.at(r,c)[0]^l; 91 | image.at(r,c)[1]=image.at(r,c)[1]^l; 92 | image.at(r,c)[2]=image.at(r,c)[2]^l; 93 | i++; 94 | } 95 | } 96 | 97 | imshow("Decrepted Diffused image", image); 98 | waitKey(0); 99 | 100 | i=511; 101 | for(int r = image.rows-1; r >= 0; --r) { 102 | for(int c = image.cols-1; c >= 0 ; --c) { 103 | if(i<0) 104 | i=511; 105 | int temps= x[i].second; 106 | 107 | pixel= image.at(r,temps); 108 | image.at(r,temps)=image.at(r,c); 109 | image.at(r,c)=pixel; 110 | 111 | i--; 112 | } 113 | } 114 | 115 | namedWindow("Decrypted", WINDOW_AUTOSIZE ); 116 | imshow("Decrypted", image); 117 | waitKey(0); 118 | 119 | return 0; 120 | 121 | } -------------------------------------------------------------------------------- /key_sensivity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeShaurya/Image-encryption/b5a3139da21c0effff34cfb09744cfe2d845d486/key_sensivity -------------------------------------------------------------------------------- /key_sensivity.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace cv; 5 | using namespace std; 6 | 7 | const int MAX=1e4+79; 8 | 9 | /** 10 | u is the control parameter for logistic chaotic map,also known as population rate 11 | Here u is taken 3.94 12 | x is the vector that contain the value generated by chaotic map 13 | The initial value of the logistic chaotic map is 0.4 14 | */ 15 | 16 | int main() 17 | { 18 | Mat image,encImage1,encImage2,tempImage; 19 | int i,l; 20 | double u1=3.94001,u2=3.94002,percenDiff,count=0; 21 | vector> x1,x2; 22 | Vec pixel,pixel1; 23 | 24 | 25 | image = imread("Image/sample_image_grey.jpg", 0 ); 26 | if ( !image.data ) 27 | { 28 | cout<<"No image data \n"; 29 | return -1; 30 | } 31 | 32 | x1.push_back({0.400001,0}); 33 | x2.push_back({0.400002,0}); 34 | 35 | // cout<511) 60 | i=0; 61 | int temps= x1[i].second; 62 | 63 | pixel= image.at(r,temps); 64 | image.at(r,temps)=image.at(r,c); 65 | image.at(r,c)=pixel; 66 | 67 | i++; 68 | } 69 | } 70 | 71 | for(int r = 0; r < image.rows; ++r) { 72 | for(int c = 0; c < image.cols; ++c) { 73 | if(i>100){ 74 | i=1; 75 | } 76 | l=x1[i].first*MAX; 77 | l=l%255; 78 | image.at(r,c)[0]=image.at(r,c)[0]^l; 79 | image.at(r,c)[1]=image.at(r,c)[1]^l; 80 | image.at(r,c)[2]=image.at(r,c)[2]^l; 81 | i++; 82 | } 83 | } 84 | encImage1=image; 85 | image=tempImage; 86 | 87 | i=0; 88 | tempImage=image; 89 | for(int r = 0; r < image.rows; ++r) { 90 | for(int c = 0; c < image.cols; ++c) { 91 | if(i>511) 92 | i=0; 93 | int temps= x2[i].second; 94 | 95 | pixel= image.at(r,temps); 96 | image.at(r,temps)=image.at(r,c); 97 | image.at(r,c)=pixel; 98 | 99 | i++; 100 | } 101 | } 102 | 103 | for(int r = 0; r < image.rows; ++r) { 104 | for(int c = 0; c < image.cols; ++c) { 105 | if(i>100){ 106 | i=1; 107 | } 108 | l=x2[i].first*MAX; 109 | l=l%255; 110 | image.at(r,c)[0]=image.at(r,c)[0]^l; 111 | image.at(r,c)[1]=image.at(r,c)[1]^l; 112 | image.at(r,c)[2]=image.at(r,c)[2]^l; 113 | i++; 114 | } 115 | } 116 | 117 | encImage2=image; 118 | image=tempImage; 119 | 120 | for(int r = 0; r < image.rows; ++r) { 121 | for(int c = 0; c < image.cols; ++c) { 122 | pixel= encImage1.at(r,c); 123 | pixel1= encImage2.at(r,c); 124 | 125 | if(pixel[0] ==pixel[0]) 126 | count +=1; 127 | if(pixel[1] ==pixel[1]) 128 | count +=1; 129 | if(pixel[2] ==pixel[2]) 130 | count +=1; 131 | } 132 | } 133 | 134 | percenDiff=count/(512*512*3)*100; 135 | cout<<"The first image and second encrypted image are "< 2 | #include 3 | 4 | using namespace cv; 5 | using namespace std; 6 | 7 | const int MAX=1e4+79; 8 | 9 | /** 10 | u is the control parameter for logistic chaotic map,also known as population rate 11 | Here u is taken 3.94 12 | x is the vector that contain the value generated by chaotic map 13 | The initial value of the logistic chaotic map is 0.4 14 | */ 15 | 16 | int main() 17 | { 18 | Mat image,encImage1,encImage2,tempImage,diffImage; 19 | int i,l; 20 | double u1=3.94001,u2=3.94002,percenDiff,count=0; 21 | vector> x1,x2; 22 | Vec pixel,pixel1; 23 | 24 | 25 | image = imread("Image/sample_image_grey.jpg", 0 ); 26 | if ( !image.data ) 27 | { 28 | cout<<"No image data \n"; 29 | return -1; 30 | } 31 | 32 | x1.push_back({0.400001,0}); 33 | x2.push_back({0.400002,0}); 34 | 35 | double temp; 36 | for (int i = 1; i <= 511; ++i){ 37 | temp=u1*x1[i-1].first*(1-x1[i-1].first); 38 | x1.push_back({temp,i}); 39 | } 40 | 41 | for (int i = 1; i <= 511; ++i){ 42 | temp=u2*x2[i-1].first*(1-x2[i-1].first); 43 | x2.push_back({temp,i}); 44 | } 45 | 46 | sort(x1.begin(), x1.end()); 47 | sort(x2.begin(), x2.end()); 48 | 49 | imshow("Original image", image); 50 | waitKey(0); 51 | 52 | i=1; 53 | 54 | tempImage = image; 55 | for(int r = 0; r < image.rows; ++r) { 56 | for(int c = 0; c < image.cols; ++c) { 57 | if(i>100){ 58 | i=1; 59 | } 60 | l=x1[i].first*MAX; 61 | l=l%255; 62 | image.at(r,c)[0]=image.at(r,c)[0]^l; 63 | image.at(r,c)[1]=image.at(r,c)[1]^l; 64 | image.at(r,c)[2]=image.at(r,c)[2]^l; 65 | i++; 66 | } 67 | } 68 | 69 | encImage1=image; 70 | image=tempImage; 71 | 72 | i = 1; 73 | 74 | for(int r = 0; r < image.rows; ++r) { 75 | for(int c = 0; c < image.cols; ++c) { 76 | if(i>100){ 77 | i=1; 78 | } 79 | l=x2[i].first*MAX; 80 | l=l%255; 81 | image.at(r,c)[0]=image.at(r,c)[0]^l; 82 | image.at(r,c)[1]=image.at(r,c)[1]^l; 83 | image.at(r,c)[2]=image.at(r,c)[2]^l; 84 | i++; 85 | } 86 | } 87 | 88 | encImage2=image; 89 | image=tempImage; 90 | 91 | for(int r = 0; r < image.rows; ++r) { 92 | for(int c = 0; c < image.cols; ++c) { 93 | pixel= encImage1.at(r,c); 94 | pixel1= encImage2.at(r,c); 95 | 96 | if(pixel[0] ==pixel[0]) 97 | count +=1; 98 | if(pixel[1] ==pixel[1]) 99 | count +=1; 100 | if(pixel[2] ==pixel[2]) 101 | count +=1; 102 | } 103 | } 104 | 105 | percenDiff=count/(512*512*3)*100; 106 | cout<<"The first image and second encrypted image are "< 2 | #include 3 | 4 | using namespace cv; 5 | using namespace std; 6 | 7 | const int MAX=1e4+79; 8 | 9 | /** 10 | u is the control parameter for logistic chaotic map,also known as population rate 11 | Here u is taken 3.94 12 | x is the vector that contain the value generated by chaotic map 13 | The initial value of the logistic chaotic map is 0.4 14 | */ 15 | 16 | int main() 17 | { 18 | Mat image,encImage1,encImage2,tempImage,diffImage; 19 | int i,l; 20 | double u1=3.94001,u2=3.94002,percenDiff,count=0; 21 | vector > x1,x2; 22 | Vec pixel,pixel1; 23 | 24 | 25 | image = imread("Image/sample_image_grey.jpg", 0 ); 26 | if ( !image.data ) 27 | { 28 | cout<<"No image data \n"; 29 | return -1; 30 | } 31 | 32 | x1.push_back({0.400001,0}); 33 | x2.push_back({0.400002,0}); 34 | 35 | double temp; 36 | for (int i = 1; i <= 511; ++i){ 37 | temp=u1*x1[i-1].first*(1-x1[i-1].first); 38 | x1.push_back({temp,i}); 39 | } 40 | 41 | for (int i = 1; i <= 511; ++i){ 42 | temp=u2*x2[i-1].first*(1-x2[i-1].first); 43 | x2.push_back({temp,i}); 44 | } 45 | 46 | sort(x1.begin(), x1.end()); 47 | sort(x2.begin(), x2.end()); 48 | 49 | imshow("Original image", image); 50 | waitKey(0); 51 | 52 | tempImage=image; 53 | 54 | i = 1; 55 | for(int r = 0; r < image.rows; ++r) { 56 | for(int c = 0; c < image.cols; ++c) { 57 | if(i>100){ 58 | i=1; 59 | } 60 | l=x1[i].first*MAX; 61 | l=l%255; 62 | image.at(r,c)[0]=image.at(r,c)[0]^l; 63 | image.at(r,c)[1]=image.at(r,c)[1]^l; 64 | image.at(r,c)[2]=image.at(r,c)[2]^l; 65 | i++; 66 | } 67 | } 68 | 69 | i=0; 70 | for(int r = 0; r < image.rows; ++r) { 71 | for(int c = 0; c < image.cols; ++c) { 72 | if(i>511) 73 | i=0; 74 | int temps= x1[i].second; 75 | 76 | pixel= image.at(r,temps); 77 | image.at(r,temps)=image.at(r,c); 78 | image.at(r,c)=pixel; 79 | 80 | i++; 81 | } 82 | } 83 | 84 | encImage1=image; 85 | image=tempImage; 86 | 87 | i = 1; 88 | tempImage=image; 89 | 90 | for(int r = 0; r < image.rows; ++r) { 91 | for(int c = 0; c < image.cols; ++c) { 92 | if(i>100){ 93 | i=1; 94 | } 95 | l=x2[i].first*MAX; 96 | l=l%255; 97 | image.at(r,c)[0]=image.at(r,c)[0]^l; 98 | image.at(r,c)[1]=image.at(r,c)[1]^l; 99 | image.at(r,c)[2]=image.at(r,c)[2]^l; 100 | i++; 101 | } 102 | } 103 | 104 | i=0; 105 | for(int r = 0; r < image.rows; ++r) { 106 | for(int c = 0; c < image.cols; ++c) { 107 | if(i>511) 108 | i=0; 109 | int temps= x2[i].second; 110 | 111 | pixel= image.at(r,temps); 112 | image.at(r,temps)=image.at(r,c); 113 | image.at(r,c)=pixel; 114 | 115 | i++; 116 | } 117 | } 118 | 119 | 120 | encImage2=image; 121 | image=tempImage; 122 | 123 | for(int r = 0; r < image.rows; ++r) { 124 | for(int c = 0; c < image.cols; ++c) { 125 | pixel= encImage1.at(r,c); 126 | pixel1= encImage2.at(r,c); 127 | 128 | if(pixel[0] ==pixel[0]) 129 | count +=1; 130 | if(pixel[1] ==pixel[1]) 131 | count +=1; 132 | if(pixel[2] ==pixel[2]) 133 | count +=1; 134 | } 135 | } 136 | 137 | percenDiff=count/(512*512*3)*100; 138 | cout<<"The first image and second encrypted image are "< 2 | #include 3 | 4 | using namespace cv; 5 | using namespace std; 6 | 7 | const int MAX=1e4+79; 8 | 9 | /** 10 | u is the control parameter for logistic chaotic map,also known as population rate 11 | Here u is taken 3.94 12 | x is the vector that contain the value generated by chaotic map 13 | The initial value of the logistic chaotic map is 0.4 14 | */ 15 | 16 | int main() 17 | { 18 | Mat image,encImage1,encImage2,tempImage,diffImage; 19 | int i,l; 20 | double u1=3.94001,u2=3.94002,percenDiff,count=0; 21 | vector> x1,x2; 22 | Vec pixel,pixel1; 23 | 24 | 25 | image = imread("Image/sample_image_grey.jpg", 0 ); 26 | if ( !image.data ) 27 | { 28 | cout<<"No image data \n"; 29 | return -1; 30 | } 31 | 32 | x1.push_back({0.400001,0}); 33 | x2.push_back({0.400002,0}); 34 | 35 | 36 | double temp; 37 | for (int i = 1; i <= 511; ++i){ 38 | temp=u1*x1[i-1].first*(1-x1[i-1].first); 39 | x1.push_back({temp,i}); 40 | } 41 | 42 | for (int i = 1; i <= 511; ++i){ 43 | temp=u2*x2[i-1].first*(1-x2[i-1].first); 44 | x2.push_back({temp,i}); 45 | } 46 | 47 | sort(x1.begin(), x1.end()); 48 | sort(x2.begin(), x2.end()); 49 | 50 | imshow("Original image", image); 51 | waitKey(0); 52 | 53 | i=0; 54 | tempImage=image; 55 | for(int r = 0; r < image.rows; ++r) { 56 | for(int c = 0; c < image.cols; ++c) { 57 | if(i>511) 58 | i=0; 59 | int temps= x1[i].second; 60 | 61 | pixel= image.at(r,temps); 62 | image.at(r,temps)=image.at(r,c); 63 | image.at(r,c)=pixel; 64 | 65 | i++; 66 | } 67 | } 68 | 69 | encImage1=image; 70 | image=tempImage; 71 | 72 | i=0; 73 | tempImage=image; 74 | for(int r = 0; r < image.rows; ++r) { 75 | for(int c = 0; c < image.cols; ++c) { 76 | if(i>511) 77 | i=0; 78 | int temps= x2[i].second; 79 | 80 | pixel= image.at(r,temps); 81 | image.at(r,temps)=image.at(r,c); 82 | image.at(r,c)=pixel; 83 | 84 | i++; 85 | } 86 | } 87 | 88 | encImage2=image; 89 | image=tempImage; 90 | 91 | for(int r = 0; r < image.rows; ++r) { 92 | for(int c = 0; c < image.cols; ++c) { 93 | pixel= encImage1.at(r,c); 94 | pixel1= encImage2.at(r,c); 95 | 96 | if(pixel[0] ==pixel[0]) 97 | count +=1; 98 | if(pixel[1] ==pixel[1]) 99 | count +=1; 100 | if(pixel[2] ==pixel[2]) 101 | count +=1; 102 | } 103 | } 104 | 105 | percenDiff=count/(512*512*3)*100; 106 | cout<<"The first image and second encrypted image are "< 2 | #include 3 | 4 | using namespace cv; 5 | using namespace std; 6 | 7 | const int MAX=1e4+79; 8 | 9 | /** 10 | u is the control parameter for logistic chaotic map,also known as population rate 11 | Here u is taken 3.94 12 | x is the vector that contain the value generated by chaotic map 13 | The initial value of the logistic chaotic map is 0.4 14 | */ 15 | 16 | int main() 17 | { 18 | Mat image,encImage1,encImage2,tempImage,diffImage; 19 | int i,l; 20 | double u1=3.94001,u2=3.94002,percenDiff,count=0; 21 | vector> x1,x2; 22 | Vec pixel,pixel1; 23 | 24 | 25 | image = imread("Image/sample_image_grey.jpg", 0 ); 26 | if ( !image.data ) 27 | { 28 | cout<<"No image data \n"; 29 | return -1; 30 | } 31 | 32 | x1.push_back({0.400001,0}); 33 | x2.push_back({0.400002,0}); 34 | 35 | // cout<511) 60 | i=0; 61 | int temps= x1[i].second; 62 | 63 | pixel= image.at(r,temps); 64 | image.at(r,temps)=image.at(r,c); 65 | image.at(r,c)=pixel; 66 | 67 | i++; 68 | } 69 | } 70 | 71 | for(int r = 0; r < image.rows; ++r) { 72 | for(int c = 0; c < image.cols; ++c) { 73 | if(i>100){ 74 | i=1; 75 | } 76 | l=x1[i].first*MAX; 77 | l=l%255; 78 | image.at(r,c)[0]=image.at(r,c)[0]^l; 79 | image.at(r,c)[1]=image.at(r,c)[1]^l; 80 | image.at(r,c)[2]=image.at(r,c)[2]^l; 81 | i++; 82 | } 83 | } 84 | encImage1=image; 85 | image=tempImage; 86 | 87 | i=0; 88 | tempImage=image; 89 | for(int r = 0; r < image.rows; ++r) { 90 | for(int c = 0; c < image.cols; ++c) { 91 | if(i>511) 92 | i=0; 93 | int temps= x2[i].second; 94 | 95 | pixel= image.at(r,temps); 96 | image.at(r,temps)=image.at(r,c); 97 | image.at(r,c)=pixel; 98 | 99 | i++; 100 | } 101 | } 102 | 103 | for(int r = 0; r < image.rows; ++r) { 104 | for(int c = 0; c < image.cols; ++c) { 105 | if(i>100){ 106 | i=1; 107 | } 108 | l=x2[i].first*MAX; 109 | l=l%255; 110 | image.at(r,c)[0]=image.at(r,c)[0]^l; 111 | image.at(r,c)[1]=image.at(r,c)[1]^l; 112 | image.at(r,c)[2]=image.at(r,c)[2]^l; 113 | i++; 114 | } 115 | } 116 | 117 | encImage2=image; 118 | image=tempImage; 119 | 120 | for(int r = 0; r < image.rows; ++r) { 121 | for(int c = 0; c < image.cols; ++c) { 122 | pixel= encImage1.at(r,c); 123 | pixel1= encImage2.at(r,c); 124 | 125 | if(pixel[0] ==pixel[0]) 126 | count +=1; 127 | if(pixel[1] ==pixel[1]) 128 | count +=1; 129 | if(pixel[2] ==pixel[2]) 130 | count +=1; 131 | } 132 | } 133 | 134 | percenDiff=count/(512*512*3)*100; 135 | cout<<"The first image and second encrypted image are "< 2 | #include 3 | 4 | using namespace cv; 5 | using namespace std; 6 | 7 | /** 8 | u is the control parameter for logistic chaotic map,also known as population rate 9 | Here u is taken 3.94 10 | x is the vector that contain the value generated by chaotic map 11 | The initial value of the logistic chaotic map is 0.4 12 | */ 13 | 14 | int main(){ 15 | 16 | Mat image,encImage1,difference_perm_diff; 17 | int n; 18 | 19 | encImage1 = imread("perm_diff_1.jpg", 0 ); 20 | if ( !image.data ) 21 | { 22 | cout<<"No image data \n"; 23 | return -1; 24 | } 25 | 26 | difference_perm_diff = imread("Image/keyspace_sensitivity/difference_perm_diff.jpg", 0 ); 27 | if ( !image.data ) 28 | { 29 | cout<<"No image data \n"; 30 | return -1; 31 | } 32 | 33 | cout<<"Enter the number of iteration you want :"; 34 | cin>>n; 35 | 36 | for (int i = 0; i < n; ++i){ 37 | image = encImage1 - difference_perm_diff; 38 | encImage1 = image; 39 | imshow("The difference image from the difference image", image); 40 | waitKey(0); 41 | } 42 | 43 | 44 | return 0; 45 | 46 | } --------------------------------------------------------------------------------