-
Notifications
You must be signed in to change notification settings - Fork 6
/
random.c
65 lines (57 loc) · 1.18 KB
/
random.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
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define bool short
char* seedname="/dev/random"; // SECURE, but SLOOOW
// char* seedname="/dev/urandom"; // FAST, but INSECURE
char* cyphername="seed.key"; // To compensate for insecurity
void create(char* filename,size_t num_bytes)
{
FILE* file=fopen(filename,"wb");
FILE* seed=fopen(seedname,"rb");
FILE* cypher=fopen(cyphername,"rb");
// if(!cypher)printf("CANT OPEN %s\n",cyphername);
long i;
int c=fgetc(seed);
int s=fgetc(seed);
srand(time(NULL));// seed
for (i = 0; i < num_bytes; i++){
s=fgetc(seed);
if(cypher){
c= fgetc(cypher);
if(i%1337==0)
srand(c^s);// re-seed
}
if(file)
fprintf(file,"%c",rand()^c^s);
else
printf("%c",rand()^c^s);
}
}
long size(FILE* fp){
fseek(fp, 0L, SEEK_END);
long sz = ftell(fp);
fseek(fp, 0L, SEEK_SET);
return sz;
}
long min(long a,long b){
return a<b?a:b;
}
void usage(){
printf("USAGE:\n random file\n");
}
bool eq(char* a,char* b){
return strstr(a,b)!=0;
}
int main(int cc,char** cv){
cc--;
if(cc>1)cyphername=cv[2];
if(cc>=1){
char* f=cv[1];
create(f,0x1000000);
}else{
create(0,0x1000000);
// usage();
}
}