Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ab43ed2

Browse files
decreption is done for encrypted image
1 parent 259f470 commit ab43ed2

File tree

1 file changed

+70
-40
lines changed

1 file changed

+70
-40
lines changed

‎decryption.cpp

Lines changed: 70 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,81 @@
1-
#include <stdio.h>
1+
#include <bits/stdc++.h>
22
#include <opencv2/opencv.hpp>
33

44
using namespace cv;
55
using namespace std;
66

77
const int MAX=1e4+79;
88

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+
916
int main()
1017
{
11-
Mat image;
12-
double x[102];
13-
double u; //u is the control parameter for chaotic map,also known as population rate
14-
15-
image = imread( "encryptedImage.jpg", 1 );
16-
if ( !image.data )
17-
{
18-
cout<<"No image data \n";
19-
return -1;
18+
Mat image;
19+
int i,l;
20+
double u=3.94;
21+
vector<pair<double,int >> x;
22+
Vec<unsigned char, 3> pixel;
23+
24+
image = imread("Image/encrypted_image.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("Decrepted image", image);
43+
waitKey(0);
44+
45+
i=1;
46+
for(int r = 0; r < image.rows; ++r) {
47+
for(int c = 0; c < image.cols; ++c) {
48+
if(i>100){
49+
i=1;
50+
}
51+
l=x[i].first*MAX;
52+
l=l%255;
53+
image.at<Vec3b>(r,c)[0]=image.at<Vec3b>(r,c)[0]^l;
54+
image.at<Vec3b>(r,c)[1]=image.at<Vec3b>(r,c)[1]^l;
55+
image.at<Vec3b>(r,c)[2]=image.at<Vec3b>(r,c)[2]^l;
56+
i++;
2057
}
21-
//Applying Logistic map
22-
u=3.94; //It is the condition for logistic map
23-
x[0]=0.4; //Base condition for logistic map
24-
for (int i = 1; i <= 100; ++i)
25-
x[i]=u*x[i-1]*(1-x[i-1]);
26-
sort(x,x+100);
27-
28-
// reading image pixel
29-
int i=1;
30-
int l;
31-
32-
for(int r = 0; r < image.rows; ++r) {
33-
for(int c = 0; c < image.cols; ++c) {
34-
if(i>100){
35-
i=1;
36-
}
37-
l=x[i]*MAX;
38-
l=l%255;
39-
// cout << "Pixel at position (x, y) : (" << c << ", " << r << ") =";
40-
image.at<Vec3b>(r,c)[0]=image.at<Vec3b>(r,c)[0]^l;
41-
image.at<Vec3b>(r,c)[1]=image.at<Vec3b>(r,c)[1]^l;
42-
image.at<Vec3b>(r,c)[2]=image.at<Vec3b>(r,c)[2]^l;
43-
i++;
44-
}
45-
}
46-
namedWindow("Shubham@shaurya", WINDOW_AUTOSIZE );
47-
imshow("Shubham@shaurya", image);
48-
waitKey(0);
49-
50-
return 0;
58+
}
59+
60+
i=511;
61+
for(int r = image.rows-1; r >= 0; --r) {
62+
for(int c = image.cols-1; c >= 0 ; --c) {
63+
if(i<0)
64+
i=511;
65+
int temps= x[i].second;
66+
67+
pixel= image.at<Vec3b>(r,temps);
68+
image.at<Vec3b>(r,temps)=image.at<Vec3b>(r,c);
69+
image.at<Vec3b>(r,c)=pixel;
70+
71+
i--;
72+
}
73+
}
74+
75+
namedWindow("Original_image", WINDOW_AUTOSIZE );
76+
imshow("Original_image", image);
77+
waitKey(0);
78+
79+
return 0;
80+
5181
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /