add pyesc, unhex, xor

This commit is contained in:
Neale Pickett 2012-02-10 11:29:56 -07:00
parent 0f907c2b11
commit 49ff09dc9e
4 changed files with 125 additions and 2 deletions

2
hd.c
View File

@ -94,5 +94,3 @@ main(int argc, char *argv[])
return 0;
}

26
pyesc.c Normal file
View File

@ -0,0 +1,26 @@
#include <stdio.h>
int
main(int argc, char *argv[])
{
while (1) {
int c = getchar();
switch (c) {
case EOF:
return 0;
case 134:
printf("\\\\");
break;
case 32 ... 91:
case 93 ... 126:
putchar(c);
break;
default:
printf("\\x%02x", c);
break;
}
}
return 0;
}

51
unhex.c Normal file
View File

@ -0,0 +1,51 @@
/* Hex Decoder -- 2012 Zephyr <zephyr@dirtbags.net>
*
* This file is in the public domain. I make no promises
* about the functionality of this program.
*/
#include <stdio.h>
int
main(int argc, char *argv[])
{
unsigned char acc = 0;
unsigned char nybble = 0;
unsigned long int count = 0;
while (1) {
int c = getchar();
count += 1;
switch (c) {
case EOF:
return 0;
case '0' ... '9':
acc = (acc << 4) + c - '0';
nybble += 1;
break;
case 'a' ... 'f':
acc = (acc << 4) + c - 'a' + 10;
nybble += 1;
break;
case 'A' ... 'F':
acc = (acc << 4) + c - 'A' + 10;
nybble += 1;
break;
default:
if (nybble != 0) {
fprintf(stderr, "Warning: non-hex character mid-octet at offset %lu\n", count);
}
break;
}
if (nybble == 2) {
putchar(acc);
acc = 0;
nybble = 0;
}
}
return 0;
}

48
xor.c Normal file
View File

@ -0,0 +1,48 @@
/* xor filter -- 2012 Zephyr <zephyr@dirtbags.net>
*
* This file is in the public domain. I make no promises
* about the functionality of this program.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
main(int argc, char *argv[])
{
int start = 1;
int base = 0;
int arg;
if (argc < 2) {
fprintf(stderr, "Usage: %s [-x] m1 [m2 ...]\n", argv[0]);
return 1;
}
if (0 == strcmp(argv[1], "-x")) {
base = 16;
start += 1;
}
arg = start;
while (1) {
int c = getchar();
unsigned char mask;
if (! argv[arg]) {
arg = start;
}
mask = strtol(argv[arg++], NULL, base);
if (EOF == c) {
break;
}
c ^= mask;
putchar(c);
}
return 0;
}