-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
87 lines (77 loc) · 2.05 KB
/
main.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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "steganography.h"
int
main (int argc, char *argv[])
{
// declare variables
char *inputFile, *messageFile, *outputFile;
// check if the arguments are valid
if (argc == 1)
{
fprintf (stderr, "Invalid arguments\n");
fprintf (stderr,
"Usage: %s -e input-file.png message.txt staged-image.png \n",
argv[0]);
fprintf (stderr, "Usage: %s -d staged-image.png \n", argv[0]);
exit (EXIT_FAILURE);
}
// assign arguments to variables
if (strcmp (argv[1], "-e") == 0)
{
// check if the arguments are valid
if (argc < 5)
{
fprintf (stderr, "Invalid arguments\n");
fprintf (stderr,
"Usage: %s -e input-file.png message.txt staged-image.png \n",
argv[0]);
exit (EXIT_FAILURE);
}
inputFile = argv[2];
messageFile = argv[3];
outputFile = argv[4];
encode (inputFile, messageFile, outputFile);
}
else if (strcmp (argv[1], "-d") == 0)
{
// check if the arguments are valid
if (argc < 3)
{
fprintf (stderr, "Invalid arguments\n");
fprintf (stderr, "Usage: %s -d staged-image.png \n", argv[0]);
fprintf (stderr, "Usage: %s -d staged-imaged.png -o output-file.txt \n",
argv[0]);
exit (EXIT_FAILURE);
}
inputFile = argv[2];
if (argc > 3 && strcmp (argv[3], "-o") == 0)
{
if (argc < 5)
{
fprintf (stderr, "Invalid arguments\n");
fprintf (stderr,
"Usage: %s -d staged-imaged.png -o output-file.txt \n",
argv[0]);
exit (EXIT_FAILURE);
}
outputFile = argv[4];
}
else
{
outputFile = "message.txt";
}
decode (inputFile, outputFile);
}
else
{
fprintf (stderr, "Invalid arguments\n");
fprintf (stderr,
"Usage: %s -e input-file.png message.txt staged-image.png \n",
argv[0]);
fprintf (stderr, "Usage: %s -d staged-image.png \n", argv[0]);
exit (EXIT_FAILURE);
}
exit (EXIT_SUCCESS);
}