-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathciphertext.c
51 lines (41 loc) · 1.04 KB
/
ciphertext.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
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "charmap.h"
#include "error.h"
#include "ciphertext.h"
/* loads ciphertext into array, [A-Za-z] are converted to 0-25 */
int *load_ciphertext(const char *filename, int *len, int resume)
{
int c;
int *ciphertext, *p_ct;
FILE *fp;
if ((fp = fopen(filename, "r")) == NULL) {
if (resume)
err_open_fatal_resume(filename);
else
err_open_fatal(filename);
}
*len = 0;
while ((c = fgetc(fp)) != EOF)
if (isalpha(c))
(*len)++;
else if (!isspace(c))
err_illegal_char_fatal(filename);
if (( ciphertext = malloc(*len*(sizeof *ciphertext)) ) == NULL)
err_alloc_fatal(filename);
rewind(fp);
p_ct = ciphertext;
while ((c = fgetc(fp)) != EOF)
if (isalpha(c))
*p_ct++ = code[c];
fclose(fp);
return ciphertext;
}
/*
* 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
*
*/