-
Notifications
You must be signed in to change notification settings - Fork 0
/
CovertSecret.cpp
56 lines (51 loc) · 1.04 KB
/
CovertSecret.cpp
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
//
// Created by Elliott on 7/7/2015.
//
#include "CovertSecret.h"
bool CovertSecret::encrypt(char in[], int in_num, char out[], int *out_num)
{
uLongf output_size = *out_num;
if(Z_OK == compress((Bytef*)(out),&output_size,(Bytef*)in,in_num))
{
*out_num = output_size;
addKey(out,*out_num);
return true;
}
else
{
printf("Compress Error\n");
return false;
}
}
bool CovertSecret::decrypt(char in[], int in_num, char out[], int *out_num)
{
uLongf output_size = *out_num;
removeKey(in,in_num);
if(Z_OK == uncompress((Bytef*)(out),&output_size,(Bytef*)in,in_num))
{
*out_num = output_size;
return true;
}
else
{
printf("Decompress Error\n");
return false;
}
}
void CovertSecret::addKey(char in[] , int in_num)
{
for(int i=0;i<in_num;i++)
{
in[i]+=key;
}
}
void CovertSecret::removeKey(char in[] , int in_num)
{
for(int i=0;i<in_num;i++)
{
in[i]-=key;
}
}
CovertSecret::CovertSecret() {
key = 7;
}