-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
86 lines (61 loc) · 1.69 KB
/
main.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
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
#include <iostream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#define MAX_FILE_SIZE (1024 * 1024)
int main (int argc, char **argv)
{
char data [MAX_FILE_SIZE];
int counter = 0;
int i = 0;
FILE *fptr;
std :: string argument = argv[1];
if (argument == "--help" || argument == "-h")
{
printf("\n");
std :: cout << "Usage: file-encode [OPTION] ... [FILE]" << std :: endl;
std :: cout << "XOR 0.x60 Encode or Decode FILE, Enter the file adress and then your file will be encrypted." << std :: endl;
std :: cout << "Mandatory arguments to long options are mandatory for short options too." << std :: endl;
std :: cout << " -d, --decode decode the file" << std :: endl;
std :: cout << " -h, --help Desplay this " << std :: endl;
return 0;
}
bool flag = false;
if (argument[0] == '-')
{
flag = true;
}
try
{
fptr = fopen (argv[1], "rb");
if (! fptr)
{
throw argv[1];
}
}
catch (char* fileName)
{
if (flag == false)
{
std :: cout << fileName << " is not valid file adress" << std :: endl;
}
else
{
std::cout << fileName << " command not found!" << std::endl;
std::cout << "File-Encode: Use --help for more information." << std::endl;
}
return 1;
}
while (!feof (fptr))
{
data[i++] = fgetc(fptr);
}
fclose (fptr);
fptr = fopen (argv[1], "wb");
for (int j = 0; j < i - 1; j++)
{
fputc ((data[j] ^ 0x60), fptr);
}
fclose (fptr);
return 0;
}