Repository navigation
Expand file tree
/
Copy pathsource.cpp
More file actions
138 lines (120 loc) · 2.25 KB
/
Copy pathsource.cpp
File metadata and controls
138 lines (120 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <iostream>
#include "Windows.h";
#include <stdio.h>
using namespace std;
void DecimalToBinary(char c, int *word);
char BinaryToChar(int *word);
int main()
{
// structures
BITMAPFILEHEADER bfh_l;
BITMAPINFOHEADER bih_l;
RGBTRIPLE rgb_l;
FILE * f1, *f2;
char*hide = new char[100];
int *word = new int[7];
f1 = fopen("6.bmp", "r+b");
f2 = fopen("4.bmp", "w+b");
fread(&bfh_l, sizeof(bfh_l), 1, f1); //BITMAPFILEHEADER
fwrite(&bfh_l, sizeof(bfh_l), 1, f2); //
fread(&bih_l, sizeof(bih_l), 1, f1); //BITMAPINFOHEADER
fwrite(&bih_l, sizeof(bih_l), 1, f2); //
size_t padding = 0;
if ((bih_l.biWidth * 3) % 4)
{
padding = 4 - (bih_l.biWidth * 3) % 4;
}
cout << "Input your word to code" << endl;
cin >> hide;
//coding
for (int i = 0; i < strlen(hide); i++)
{
DecimalToBinary(hide[i], word);
for (int j = 0; j < 7; j++)
{
fread(&rgb_l, sizeof(rgb_l), 1, f1);
if (word[j] == 1)
{
if (rgb_l.rgbtRed % 2 != 1)
{
rgb_l.rgbtRed++;
}
}
else
{
if (rgb_l.rgbtRed % 2 != 0)
{
rgb_l.rgbtRed++;
}
}
fwrite(&rgb_l, sizeof(rgb_l), 1, f2);
}
}
while (!feof(f1))
{
fread(&rgb_l, sizeof(rgb_l), 1, f1);
fwrite(&rgb_l, sizeof(rgb_l), 1, f2);
if (padding != 0)
{
fread(&rgb_l, padding, 1, f1);
fwrite(&rgb_l, padding, 1, f2);
}
}
_fcloseall();
f2 = fopen("4.bmp", "r");
fread(&bfh_l, sizeof(bfh_l), 1, f2);
fread(&bih_l, sizeof(bih_l), 1, f2);
//decoding
cout << "Decoding... decoding..." << endl;
cout << "and the word was: ";
for (int i = 0; i < strlen(hide) * 7; i++)
{
fread(&rgb_l, sizeof(rgb_l), 1, f2);
if (rgb_l.rgbtRed % 2 == 1)
{
word[i % 7] = 1;
}
else
{
word[i % 7] = 0;
}
if (i % 7 == 6)
{
cout << BinaryToChar(word);
for (int j = 0; j < 7; j++)
{
word[j] = 0;
}
}
}
cout << endl;
fclose(f2);
delete[] word; delete[] hide;
system("pause");
return 0;
}
void DecimalToBinary(char c, int *word)
{
for (int j = 0; j < 7; j++)
{
word[j] = 0;
}
int number = (int)c;
int i = 6;
while (number != 0)
{
word[i] = number % 2;
number /= 2;
i--;
}
}
char BinaryToChar(int *word)
{
char n = 0,mn=64;
for (int i = 0; i < 7; i++)
{
n += word[i]*mn;
mn /= 2;
}
return n;
}