-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_encode.c
140 lines (119 loc) · 3.67 KB
/
test_encode.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
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
#include <stdio.h>
#include "encode.h"
#include "types.h"
#include <string.h>
#include "common.h"
#include "decode.h"
int main(int argc , char *argv[])
{
int option=check_operation_type(argv); //function call to check the operation type
if(option==e_encode){ //if the selected option is encode
EncodeInfo encInfo; //declaring the structure variable as encInfo
printf("Encoding selected\n");
if((read_and_validate_encode_args(argv,&encInfo))==e_success) //reading and validating all the arguments
{
printf("Successfully read and validated\n");
if(open_files(&encInfo)==e_success) //openning all the neccessary files
{
printf("Files opened successfully\n");
if(check_capacity(&encInfo)==e_success) //checking if the bmp file is compactable to store the secret file
{
printf("File has the neccessary capacity\n");
if(copy_bmp_header(encInfo.fptr_src_image,encInfo.fptr_stego_image)==e_success) //coping the heaer file of original image to new image
{
printf("header contents copied successfully\n");
if(encode_magic_string(MAGIC_STRING,&encInfo)==e_success) //encoded the magic string to the new image
{
printf("Magic string copied succesfully\n");
if(encode_secret_file_extn_size(strlen(encInfo.extn_secret_file),encInfo.fptr_src_image,encInfo.fptr_stego_image)==e_success) //size of secret file extension encoded
{
printf("Secret file extention size encoded succesfully\n");
if(encode_secret_file_extn(encInfo.extn_secret_file,&encInfo)==e_success) //secret file extension encoded
{
printf("Secret file extention encoded successfully\n");
if(encode_secret_file_size(encInfo.size_secret_file,&encInfo)==e_success) //secret file size encoded
{
printf("Secret file size encoded succesfully\n");
if(encode_secret_file_data(&encInfo)==e_success) //secret file data encoded to the new image
{
printf("Secret file data encoded succesfully\n");
if(copy_remaining_img_data(encInfo.fptr_src_image,encInfo.fptr_stego_image)==e_success) //the remaining data is copied as it is to the new image
{
printf("Reamaining data copied\n");
}
else
{
printf("Error\n");
}
}
else
{
printf("Error\n");
}
}
else
{
printf("error\n");
}
}
else
{
printf("error\n");
}
}
else
{
printf("error\n");
}
}
else
{
printf("error \n");
}
}
else
{
printf("error\n");
}
}
else
{
printf("File capacity check failed\n");
}
}
}
else
{
printf("Read and validation failed\n");
}
}
else if(option ==e_decode) //checking if decode is selected
{
DecodeInfo decInfo; //declaring the structure variable as decInfo
printf("selected decoding");
if(read_and_validate_decode_args(argv,&decInfo)==e_success) //reading and validating the arguments for decoding
{
printf("Read and validate success\n");
do_decoding(&decInfo); //function call to start the decoding
}
}
else //if the entered option is neither encoding or decoding
{
printf("please pass the valid option");
}
}
OperationType check_operation_type(char *argv[]) //function to check the operation type
{
if(!strcmp(argv[1],"-e"))
{
return e_encode;
}
else if(!strcmp(argv[1],"-d"))
{
return e_decode;
}
else
{
return e_unsupported;
}
}