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 c1ebcae

Browse files
Encryption and decryption is done in one file 😃
1 parent 91cd0ad commit c1ebcae

File tree

1 file changed

+104
-29
lines changed

1 file changed

+104
-29
lines changed

‎encryption.cpp

Lines changed: 104 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,128 @@
11
#include <stdio.h>
2+
#include <bits/stdc++.h>
23
#include <opencv2/opencv.hpp>
34

45
using namespace cv;
56
using namespace std;
67

78
const int MAX=1e4+79;
9+
bool flag[513][513];
810

911
int main()
1012
{
11-
Mat image;
12-
double x[102];
13-
double u; //u is the control parameter for chaotic map,also known as population rate
13+
Mat image;
14+
vector<pair<double,int >> x;
15+
double u=3.94,hold,temp; //u is the control parameter for chaotic map,also known as population rate
1416

15-
image = imread( "Image.jpg", 1 );
17+
image = imread( "Image/sample_image_grey.jpg", 1 );
1618
if ( !image.data )
1719
{
18-
cout<<"No image data \n";
19-
return -1;
20+
cout<<"No image data \n";
21+
return -1;
2022
}
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
23+
24+
x.push_back({0.4,0});
25+
memset(flag ,false,sizeof(flag));
26+
27+
for (int i = 1; i <= 511; ++i){
28+
temp=x[i-1].first;
29+
hold=u*temp*(1-temp);
30+
x.push_back({hold,i});
31+
}
32+
sort(x.begin(), x.end());
33+
2934
int i=1;
3035
int l;
3136

37+
imshow("Shubham@shaurya", image);
38+
waitKey(0);
39+
40+
i=0;
41+
int holds[4];
3242
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-
}
43+
for(int c = 0; c < image.cols; ++c) {
44+
if(i>511)
45+
i=0;
46+
int temps= x[i].second;
47+
48+
holds[0]= image.at<Vec3b>(r,temps)[0];
49+
image.at<Vec3b>(r,temps)[0]=image.at<Vec3b>(r,c)[0];
50+
image.at<Vec3b>(r,c)[0]=holds[0];
51+
52+
holds[1]= image.at<Vec3b>(r,temps)[1];
53+
image.at<Vec3b>(r,temps)[1]=image.at<Vec3b>(r,c)[1];
54+
image.at<Vec3b>(r,c)[1]=holds[1];
55+
56+
57+
holds[2]= image.at<Vec3b>(r,temps)[2];
58+
image.at<Vec3b>(r,temps)[2]=image.at<Vec3b>(r,c)[2];
59+
image.at<Vec3b>(r,c)[2]=holds[2];
60+
61+
i++;
62+
}
4563
}
46-
47-
imwrite("encryptedImage.jpg",image);
64+
65+
for(int r = 0; r < image.rows; ++r) {
66+
for(int c = 0; c < image.cols; ++c) {
67+
if(i>100){
68+
i=1;
69+
}
70+
l=x[i].first*MAX;
71+
l=l%255;
72+
image.at<Vec3b>(r,c)[0]=image.at<Vec3b>(r,c)[0]^l;
73+
image.at<Vec3b>(r,c)[1]=image.at<Vec3b>(r,c)[1]^l;
74+
image.at<Vec3b>(r,c)[2]=image.at<Vec3b>(r,c)[2]^l;
75+
i++;
76+
}
77+
}
78+
79+
80+
imwrite("Image/encrypted_image.jpg",image);
81+
imshow("Shubham@shaurya", image);
82+
waitKey(0);
83+
84+
i=1;
85+
for(int r = 0; r < image.rows; ++r) {
86+
for(int c = 0; c < image.cols; ++c) {
87+
if(i>100){
88+
i=1;
89+
}
90+
l=x[i].first*MAX;
91+
l=l%255;
92+
image.at<Vec3b>(r,c)[0]=image.at<Vec3b>(r,c)[0]^l;
93+
image.at<Vec3b>(r,c)[1]=image.at<Vec3b>(r,c)[1]^l;
94+
image.at<Vec3b>(r,c)[2]=image.at<Vec3b>(r,c)[2]^l;
95+
i++;
96+
}
97+
}
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+
holds[0]= image.at<Vec3b>(r,temps)[0];
107+
image.at<Vec3b>(r,temps)[0]=image.at<Vec3b>(r,c)[0];
108+
image.at<Vec3b>(r,c)[0]=holds[0];
109+
110+
holds[1]= image.at<Vec3b>(r,temps)[1];
111+
image.at<Vec3b>(r,temps)[1]=image.at<Vec3b>(r,c)[1];
112+
image.at<Vec3b>(r,c)[1]=holds[1];
113+
114+
115+
holds[2]= image.at<Vec3b>(r,temps)[2];
116+
image.at<Vec3b>(r,temps)[2]=image.at<Vec3b>(r,c)[2];
117+
image.at<Vec3b>(r,c)[2]=holds[2];
118+
119+
i--;
120+
}
121+
}
122+
48123
namedWindow("Shubham@shaurya", WINDOW_AUTOSIZE );
49124
imshow("Shubham@shaurya", image);
50125
waitKey(0);
51126

52127
return 0;
53-
}
128+
}

0 commit comments

Comments
(0)

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