-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstesd.cpp
125 lines (90 loc) · 2.38 KB
/
stesd.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
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
/* stesd.cpp
Copyright (c) 2000 Philip Hunt
Program to decrtpy a stes ciphertext file.
Usage:
stesc ctf k pt
where:
ctf = ciphertext filename (already exists)
k = key to use to decode ctf
pt = filename that rthe result will be upt into
Last altered: 26-Jul-2000
History:
21-Jul-2000 PH: created
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <vector.h>
#include "crypt.h"
#include "checkitem.h"
#include "dataitem.h"
#define DEBUG 1
/*****
If set, this causes all CA information to be output, decrypted,
to the file ``CA.plain''. This obviously renders encryption useless
& is intended for debugging only.
*****/
#define DEBUG_OUTPUT_CA 1
//--------------------------------------------------------------------
/* global variables */
char* ctf;
char* key;
char* ptf;
//--------------------------------------------------------------------
void initializeVars(){
//int i;
}
//--------------------------------------------------------------------
void usage(){
//...to do...
}
void decodeArgs(int argc, char** argv){
#if DEBUG
for (int ix = 0; ix < argc; ix++){
printf("argv[%d]={%s}\n", ix, argv[ix]);
}
#endif
ctf = argv[1];
key = argv[2];
ptf = argv[3];
}
//--------------------------------------------------------------------
int main(int argc, char** argv){
int i;
initializeVars();
decodeArgs(argc, argv);
FILE* ctFile;
ctFile = fopen(ctf, "r");
/* set up decryption engine */
Crypt decrypt((uchar*)key);
#if DEBUG
OFile debug("dDebug");
debug << "*** writing debug info from stesd ***\n\n";
#endif
/* go through each CI in turn, until one is found that successfully
decrypts: */
CheckItem ci;
bool valid;
for (i = 0; i < CA_ITEMS; i++){
valid = ci.loadFromCtf(ctFile, i, decrypt);
#if DEBUG
debug << "\nCI #" << i << ":\n";
ci.outDebugInfo(debug);
#endif
if (valid) break;
}//for i
if (!valid) {
printf("stesd: key `%s' not valid, aborting.\n", key);
exit(1);
}
/* we have the CI, now read it's DI's, one at a time, to produce
the plaintext */
FILE* ptFile;
ptFile = fopen(ptf, "w");
ci.decodePlaintextToFile(ctFile, ptFile, decrypt);
fclose(ptFile);
fclose(ctFile);
exit(0);
}
//--------------------------------------------------------------------
/* end stesd.cpp */