|
|
1.1 root 1: #include <stdio.h>
2:
3: /*
4: * security - an authentication server
5: *
6: * For a given user, this locates that user's key in the
7: * key database, challenges the user to encrypt some data,
8: * and compares that user's result with the result of
9: * encrypting the data with the user's real key. If the
10: * results are the same, the user is authenticated, otherwise,
11: * no.
12: */
13: main()
14: {
15: int k[8], i, j;
16: char s[30], c[30], b[64];
17: unsigned l, r;
18:
19: puts("key: 8 groups of three octal digits");
20: puts("data: a decimal integer, up to 8 digits");
21: puts("");
22: fputs("key: ", stdout);
23:
24: scanf("%o %o %o %o %o %o %o %o", &k[0], &k[1], &k[2], &k[3],
25: &k[4], &k[5], &k[6], &k[7]);
26: gets(s);
27: for(i=0; i<8; i++)
28: for(j=0; j<8; j++)
29: b[8*i+j] = (k[i]>>(7-j))&1;
30: setkey(b);
31: while(1){
32: fputs("data: ", stdout);
33: for(i=0; i<8; i++) s[i] = 0;
34: gets(s);
35: for(i=0; i<8; i++)
36: for(j=0; j<8; j++)
37: b[8*i+j] = (s[i]>>(7-j))&1;
38: encrypt(b, 0);
39: for(i=0; i<32; i++){
40: l = (l<<1) | b[i];
41: r = (r<<1) | b[i+32];
42: }
43: printf("%.8x %.8x\n", l, r);
44: }
45: }
46:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.