-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstealth.cpp
More file actions
148 lines (137 loc) · 3.22 KB
/
stealth.cpp
File metadata and controls
148 lines (137 loc) · 3.22 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
139
140
141
142
143
144
145
146
147
148
#include "stealth.h"
#include "string.h"
#include "fstream"
#include "bitset"
using namespace std;
typedef struct header_file
{
char chunk_id[4];
int chunk_size;
char format[4];
char subchunk1_id[4];
int subchunk1_size;
short int audio_format;
short int num_channels;
int sample_rate; // sample_rate denotes the sampling rate.
int byte_rate;
short int block_align;
short int bits_per_sample;
char subchunk2_id[4];
int subchunk2_size; // subchunk2_size denotes the number of samples.
} header;
typedef struct header_file* header_p;
Stealth::Stealth()
{
inputfilename = "";
outputfilename = "";
Message = "";
}
void Stealth::Setinput(QString d)
{
inputfilename = d;
}
void Stealth::Setmessage(QString m)
{
Message = m;
}
void Stealth::Setoutput(QString o)
{
outputfilename = o;
}
int Stealth::Encode()
{
FILE * infile;
FILE * outfile;
const string strt = inputfilename.toStdString();
const char * str1 = strt.c_str();
infile = fopen(str1, "rb");
const string str3 = outputfilename.toStdString();
const char * str2 = str3.c_str();
outfile = fopen(str2, "wb");
int BUFSIZE = 16;
unsigned long count = 0;
bitset<8> message;
bitset<16> buffer;
short int buff16[BUFSIZE];
int nb;
string str = Message.toStdString();
if (infile)
{
while (!feof(infile))
{
nb = fread(buff16,1,BUFSIZE,infile);
/* Insert your processing code here*/
if (count == 3)
{
message = str.length();
buffer = buff16[1];
for (int i = 0; i < 8; i++)
{
buffer[i] = message[i];
}
buff16[1] = buffer.to_ulong();
}
if (count<str.length()+5 && count > 4)
{
message = str[count-5];
buffer = buff16[1];
for (int i = 0; i < 8; i++)
{
buffer[i] = message[i];
}
buff16[1] = buffer.to_ulong();
//char c = message.to_ullong();
}
fwrite(buff16,1,nb,outfile); // Writing read data into output file
count++;
}
}
return 0;
}
QString Stealth::Decode()
{
FILE * infile;
int BUFSIZE = 16;
int count = 0;
int flag;
flag = 0;
char c;
string str1;
bitset<8> message;
bitset<16> buffer;
short int buff16[BUFSIZE];
int nb;
long len;
const string strt = inputfilename.toStdString();
const char * strf = strt.c_str();
infile = fopen(strf, "rb");
if (infile)
{
while (!feof(infile))
{
nb = fread(buff16,1,BUFSIZE,infile);
if (count == 3)
{
buffer = buff16[1];
for (int i = 0; i < 8; i++)
{
message[i] = buffer[i];
}
len = message.to_ulong();
}
if (count < len+5 && count > 4)
{
buffer = buff16[1];
for (int i = 0; i < 8; i++)
{
message[i] = buffer[i];
}
c = message.to_ullong();
str1 += c;
}
count++;
}
}
QString st = QString::fromStdString(str1);
return st;
}