summaryrefslogtreecommitdiff
path: root/src/usr.bin/nc/data/xor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/usr.bin/nc/data/xor.c')
-rw-r--r--src/usr.bin/nc/data/xor.c94
1 files changed, 0 insertions, 94 deletions
diff --git a/src/usr.bin/nc/data/xor.c b/src/usr.bin/nc/data/xor.c
deleted file mode 100644
index 2fed291173..0000000000
--- a/src/usr.bin/nc/data/xor.c
+++ /dev/null
@@ -1,94 +0,0 @@
1/* $OpenBSD: xor.c,v 1.3 2001/11/19 19:02:15 mpech Exp $ */
2
3/* Generic xor handler.
4
5 With no args, xors stdin against 0xFF to stdout. A single argument is a
6 file to read xor-bytes out of. Any zero in the xor-bytes array is treated
7 as the end; if you need to xor against a string that *includes* zeros,
8 you're on your own.
9
10 The indirect file can be generated easily with data.c.
11
12 Written because there are so many lame schemes for "masking" plaintext
13 passwords and the like floating around, and it's handy to just run an
14 obscure binary-format configuration file through this and look for strings.
15
16 *Hobbit*, 960208 */
17
18#include <stdio.h>
19#include <fcntl.h>
20
21char buf[8192];
22char bytes[256];
23char * py;
24
25/* do the xor, in place. Uses global ptr "py" to maintain "bytes" state */
26xorb (buf, len)
27 char * buf;
28 int len;
29{
30 int x;
31 char * pb;
32
33 pb = buf;
34 x = len;
35 while (x > 0) {
36 *pb = (*pb ^ *py);
37 pb++;
38 py++;
39 if (! *py)
40 py = bytes;
41 x--;
42 }
43} /* xorb */
44
45/* blah */
46main (argc, argv)
47 int argc;
48 char ** argv;
49{
50 int x = 0;
51 int y;
52
53/* manually preload; xor-with-0xFF is all too common */
54 memset (bytes, 0, sizeof (bytes));
55 bytes[0] = 0xff;
56
57/* if file named in any arg, reload from that */
58#ifdef O_BINARY /* DOS shit... */
59 x = setmode (0, O_BINARY); /* make stdin raw */
60 if (x < 0) {
61 fprintf (stderr, "stdin binary setmode oops: %d\n", x);
62 exit (1);
63 }
64 x = setmode (1, O_BINARY); /* make stdout raw */
65 if (x < 0) {
66 fprintf (stderr, "stdout binary setmode oops: %d\n", x);
67 exit (1);
68 }
69#endif /* O_BINARY */
70
71 if (argv[1])
72#ifdef O_BINARY
73 x = open (argv[1], O_RDONLY | O_BINARY);
74#else
75 x = open (argv[1], O_RDONLY);
76#endif
77 if (x > 0) {
78 read (x, bytes, 250); /* nothin' fancy here */
79 close (x);
80 }
81 py = bytes;
82 x = 1;
83 while (x > 0) {
84 x = read (0, buf, sizeof (buf));
85 if (x <= 0)
86 break;
87 xorb (buf, x);
88 y = write (1, buf, x);
89 if (y <= 0)
90 exit (1);
91 }
92 exit (0);
93}
94