Skip to content

Commit c5bfa5b

Browse files
committed
Keyspace sensitivity test is commpleted with a test utility
1 parent 8ebab7d commit c5bfa5b

24 files changed

+811
-0
lines changed
259 KB
Loading
134 KB
Loading
258 KB
Loading
258 KB
Loading
3.32 KB
Loading
3.32 KB
Loading
3.32 KB
Loading
135 KB
Loading
135 KB
Loading

encryption/decryption.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include <bits/stdc++.h>
2+
#include <opencv2/opencv.hpp>
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<pair<double,int >> x;
23+
Vec<unsigned char, 3> 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<Vec3b>(r,c)[0]=image.at<Vec3b>(r,c)[0]^l;
55+
image.at<Vec3b>(r,c)[1]=image.at<Vec3b>(r,c)[1]^l;
56+
image.at<Vec3b>(r,c)[2]=image.at<Vec3b>(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<Vec3b>(r,temps);
69+
image.at<Vec3b>(r,temps)=image.at<Vec3b>(r,c);
70+
image.at<Vec3b>(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+
}

0 commit comments

Comments
 (0)