-
Notifications
You must be signed in to change notification settings - Fork 0
/
Steganography.c
100 lines (77 loc) · 2.24 KB
/
Steganography.c
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
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void encoder();
void decoder();
int main(){
char input, isDone = 0;
do{
printf("What kind of function are you perfer?\nencode[1]\ndecode[2]\ninput: ");
scanf("%c", &input);
if(input == '1'){
encoder();
isDone = 1;
} else if(input == '2'){
decoder();
isDone = 1;
} else {
printf("Your input did not match any function.\n");
getchar();
}
} while(!isDone);
return 0;
}
void encoder(){
FILE* datas = fopen("./origin.gif", "rb");
unsigned int size, counter;
unsigned int textSize;
unsigned int position;
fseek(datas, 0, SEEK_END);
size = ftell(datas);
rewind(datas);
char data[size];
fread(&(data[0]), 1, size, datas);
fclose(datas);
printf("How much length do you perfer?: ");
scanf("%u", &textSize);
getchar();
char text[textSize + 1];
printf("Please give your favor message: ");
scanf("%[0-9a-zA-Z ]s", &(text[0]));
srand(time(NULL));
do{
position = rand() % size;
} while(size < textSize + position && textSize < size); //size - position < textSize
for(counter = 0; counter < textSize && counter < size; counter++){
data[position] = text[counter];
position = position + 1;
}
datas = fopen("./modified.gif", "wb");
fwrite(&(data[0]), 1, size, datas);
fclose(datas);
return;
}
void decoder(){
FILE* originDatas = fopen("./origin.gif", "rb");
FILE* newDatas = fopen("./modified.gif", "rb");
char oldData, newData;
unsigned int size, counter;
unsigned char hasMessage = 0;
fseek(originDatas, 0, SEEK_END);
size = ftell(originDatas);
rewind(originDatas);
for(counter = 0; counter < size; counter++){
fread(&oldData, 1, 1, originDatas);
fread(&newData, 1, 1, newDatas);
if(oldData != newData && hasMessage == 0){
printf("There is a message: ");
hasMessage = 1;
}
if(oldData != newData) printf("%c", newData);
}
if(!hasMessage) printf("There is no a message.");
fclose(originDatas);
fclose(newDatas);
printf("\n");
return;
}