-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKEYMAKE.C
119 lines (77 loc) · 1.64 KB
/
KEYMAKE.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 "stdlib.h"
#include "math.h"
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
uchar select(uchar seed,uchar *lookup,uchar lenth);
int block(uchar *inbuff,uchar *outbuff);
int make(FILE *infile,FILE *outfile);
uint *getseeds(FILE *infile);
int file_error();
main(int numargs,char *args[])
{
FILE *infile;
FILE *outfile;
if (args[1]==NULL)
{
puts("You didn't specify a file name.");
exit(2);
}
printf("Creating key from:%s\n\n",args[1]);
outfile=fopen("key.fil","wb");
if (!outfile)
file_error();
infile=fopen(args[1],"rb");
if (!infile)
file_error();
getseeds(infile);
make(infile,outfile);
fcloseall();
}
int file_error()
{
perror("An error occured opening a file");
exit(1);
return 0;
}
uint *getseeds(FILE *infile)
{
int seed;
fread(&seed,2,1,infile);
srand(seed);
fseek(infile,0,SEEK_SET);
}
int make(FILE *infile,FILE *outfile)
{
uint loop;
uchar *inbuff=malloc(256);
uchar *outbuff=malloc(256);
puts("Making Key File");
for (loop=0;loop<=255;loop++)
{
printf(".");
fread(inbuff,256,1,infile);
block(inbuff,outbuff);
fwrite(outbuff,256,1,outfile);
}
puts("Done!\n");
return 0;
}
int block(uchar *inbuff,uchar *outbuff)
{
int loop;
uchar lookup[256];
for (loop=0;loop<=255;loop++)
lookup[loop]=loop;
for (loop=255;loop>=0;loop--)
*(outbuff+loop)=select((rand()+*(inbuff+loop))%(loop+1),lookup,loop);
return 0;
}
uchar select(uchar seed,uchar *lookup,uchar lenth)
{
uchar ret_val;
ret_val=*(lookup+seed);
*(lookup+seed)=*(lookup+lenth);
return ret_val;
}