-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathueb15.c
70 lines (57 loc) · 1.16 KB
/
ueb15.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
#include <stdio.h>
#include <stdlib.h>
void file_error() {
printf("Datei nicht lesbar\n");
exit(1);
}
/* may do sth more/else soon */
int printfilecontent(char* filename){
FILE* ifp;
ifp = fopen(filename, "r");
char c;
if (ifp == NULL) file_error();
while(fscanf(ifp, "%c", &c) != EOF) {
printf("%c", c);
}
fclose(ifp);
return 0;
}
char encaesar(char t, int c){
return t = t + c % 128;
}
char decaesar(char t, int c){
t = t - c + 128 % 128;
if (t<10) t+=117;
if (t>127) t-=c;
return t;
}
int printfiledeciphered(char* filename, int cipher){
FILE* ifp;
ifp = fopen(filename, "r");
char c;
if (ifp == NULL) file_error();
while(fscanf(ifp, "%c", &c) != EOF) {
printf("%c", decaesar(c, cipher));
}
fclose(ifp);
return 0;
}
int main() {
int i;
if(0 != printfilecontent("textfile.txt")){
return 1;
}
//int chiffre=0;
//printf("\n\nGeben Sie eine Chiffre an: ");
//while(!(chiffre >= 10 && chiffre <= 126)){ scanf("%d", &chiffre); }
//for(i=0; i<=26;i++){
i=12;
//printf("\n\n%d: ", i);
if(0 != printfiledeciphered("bsp.txt", i)){
return 1;
}
//}
// char* text="Klardoch!";
// for(i=0;i<9;i++) printf("%c", text+i);
return 0;
}