-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresult.c
119 lines (103 loc) · 2.31 KB
/
result.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
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include "charmap.h"
#include "date.h"
#include "error.h"
#include "global.h"
#include "key.h"
#include "result.h"
#ifndef PATH_MAX
#define PATH_MAX 260
#endif
extern int path_lookup[][26];
FILE *open_outfile(char *s)
{
FILE *fp = NULL;
if ( (strlen(s) > PATH_MAX) || (fp = fopen(s, "a")) == NULL)
err_open_fatal(s);
return fp;
}
void print_plaintext(FILE *fp, const int *stbrett, const int *ciphertext, int len)
{
int i;
int c;
#ifndef WINDOWS
int ofd;
#endif
for (i = 0; i < len; i++) {
c = stbrett[ciphertext[i]];
c = path_lookup[i][c];
c = stbrett[c];
fputc(alpha[c], fp);
}
fputc('\n', fp);
fputc('\n', fp);
fputc('\n', fp);
fflush(fp);
#ifndef WINDOWS
ofd = fileno(fp);
fsync(ofd);
#endif
}
void print_key(FILE *fp, const Key *key)
{
char date[DATELEN];
char stecker[27];
int i;
#ifndef WINDOWS
int ofd;
#endif
datestring(date);
fprintf(fp, "Date: %s\n", date);
for (i = 0; i < key->count; i++)
stecker[i] = toupper(alpha[key->sf[i]]);
stecker[i] = '\0';
if (key->model != M4) {
fprintf(fp,
"Score: %d\n\
UKW: %c\n\
W/0: %d%d%d\n\
Stecker: %s\n\
Rings: %c%c%c\n\
Message key: %c%c%c\n\n",
key->score,
toupper(alpha[key->ukwnum]),
key->l_slot, key->m_slot, key->r_slot,
stecker,
toupper(alpha[key->l_ring]), toupper(alpha[key->m_ring]),
toupper(alpha[key->r_ring]),
toupper(alpha[key->l_mesg]), toupper(alpha[key->m_mesg]),
toupper(alpha[key->r_mesg]));
}
else {
fprintf(fp,
"Score: %d\n\
UKW: %c\n\
W/0: %c%d%d%d\n\
Stecker: %s\n\
Rings: %c%c%c%c\n\
Message key: %c%c%c%c\n\n",
key->score,
key->ukwnum == 3 ? 'B' : 'C',
key->g_slot == 9 ? 'B' : 'G', key->l_slot, key->m_slot, key->r_slot,
stecker,
toupper(alpha[key->g_ring]), toupper(alpha[key->l_ring]),
toupper(alpha[key->m_ring]), toupper(alpha[key->r_ring]),
toupper(alpha[key->g_mesg]), toupper(alpha[key->l_mesg]),
toupper(alpha[key->m_mesg]), toupper(alpha[key->r_mesg]));
}
fflush(fp);
#ifndef WINDOWS
ofd = fileno(fp);
fsync(ofd);
#endif
}
/*
* This file is part of enigma-suite-0.76, which is distributed under the terms
* of the General Public License (GPL), version 2. See doc/COPYING for details.
*
* Copyright (C) 2005 Stefan Krah
*
*/