From OESF
/*
* Encode Decode shell script Ver 0.1
*----------------------------------------------------------------------------
* Copyright 2003 T.Yamashita
*
* This program is a no guarantee.
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <stdio.h>
#include <string.h>
unsigned char enctable[256]={
0x84,0x26,0xa7,0x29,0x10,0xba,0x1d,0xa4,0x15,0x0a,0x2f,0x74,0x0d,0x0e,0xdc,0xd2,
0x14,0x40,0xbc,0xb1,0x45,0x16,0x17,0x54,0xd9,0x0c,0x96,0xb2,0x8b,0xb4,0xc3,0x1b,
0x41,0x22,0x13,0x24,0xa1,0x38,0x27,0x44,0x19,0x34,0x81,0x36,0xed,0x2e,0x0b,0xc7,
0xac,0xc9,0x23,0x2a,0x35,0x2c,0xb6,0x6c,0x79,0xee,0x71,0x6d,0xd1,0x48,0x3b,0xe2,
0x5f,0x42,0x37,0xcd,0xd0,0x90,0xa5,0x88,0x85,0x7c,0x00,0xcb,0x4d,0x4e,0x82,0xfb,
0x80,0x51,0x97,0xb9,0xdd,0x56,0x93,0x7a,0x61,0x5a,0x5b,0x5c,0xf8,0x5e,0xf9,0x28,
0xf0,0xe9,0x03,0xb0,0x60,0xec,0x39,0xca,0x73,0xa8,0x6b,0x12,0x31,0xe4,0x30,0x25,
0xe7,0xc0,0x9d,0x6e,0x3e,0x50,0x77,0x02,0xbd,0x58,0x7f,0xd8,0x0f,0x9c,0x92,0x4b,
0x49,0xf1,0x57,0x1a,0xaf,0xeb,0x87,0x3c,0x70,0xf2,0xf7,0x8c,0x8d,0x8e,0xb7,0xbe,
0x91,0x1c,0x8f,0x94,0x89,0x7e,0x7d,0x98,0x09,0x9a,0x6f,0xc8,0x9f,0x9e,0xc4,0xfc,
0x8a,0xa2,0xa3,0x68,0xc5,0xa6,0x53,0xd7,0xe1,0xaa,0xd4,0x64,0x2d,0x69,0x66,0xb5,
0x04,0xfd,0xb3,0x43,0x3d,0x9b,0x2b,0xb8,0x5d,0x18,0xad,0xbb,0x99,0x20,0xbf,0xc1,
0x65,0x46,0xf3,0xce,0x33,0x63,0x21,0x76,0x52,0x3a,0x4f,0xcc,0xe5,0x47,0xcf,0x4c,
0xda,0x08,0xd3,0xab,0xd5,0x4a,0xae,0x86,0x06,0xfa,0xdb,0x83,0x59,0x7b,0xdf,0xe0,
0x11,0x72,0xe3,0x05,0xc2,0xc6,0xa9,0xe8,0x1f,0xea,0x6a,0x67,0x75,0xd6,0xef,0x95,
0x55,0xde,0x3f,0xf4,0xf5,0xf6,0x07,0x01,0xe6,0x78,0x1e,0xa0,0x32,0xfe,0xff,0x62
};
unsigned char dectable[256]={
0x4a,0xf7,0x77,0x62,0xb0,0xe3,0xd8,0xf6,0xd1,0x98,0x09,0x2e,0x19,0x0c,0x0d,0x7c,
0x04,0xe0,0x6b,0x22,0x10,0x08,0x15,0x16,0xb9,0x28,0x83,0x1f,0x91,0x06,0xfa,0xe8,
0xbd,0xc6,0x21,0x32,0x23,0x6f,0x01,0x26,0x5f,0x03,0x33,0xb6,0x35,0xac,0x2d,0x0a,
0x6e,0x6c,0xfc,0xc4,0x29,0x34,0x2b,0x42,0x25,0x66,0xc9,0x3e,0x87,0xb4,0x74,0xf2,
0x11,0x20,0x41,0xb3,0x27,0x14,0xc1,0xcd,0x3d,0x80,0xd5,0x7f,0xcf,0x4c,0x4d,0xca,
0x75,0x51,0xc8,0xa6,0x17,0xf0,0x55,0x82,0x79,0xdc,0x59,0x5a,0x5b,0xb8,0x5d,0x40,
0x64,0x58,0xff,0xc5,0xab,0xc0,0xae,0xeb,0xa3,0xad,0xea,0x6a,0x37,0x3b,0x73,0x9a,
0x88,0x3a,0xe1,0x68,0x0b,0xec,0xc7,0x76,0xf9,0x38,0x57,0xdd,0x49,0x96,0x95,0x7a,
0x50,0x2a,0x4e,0xdb,0x00,0x48,0xd7,0x86,0x47,0x94,0xa0,0x1c,0x8b,0x8c,0x8d,0x92,
0x45,0x90,0x7e,0x56,0x93,0xef,0x1a,0x52,0x97,0xbc,0x99,0xb5,0x7d,0x72,0x9d,0x9c,
0xfb,0x24,0xa1,0xa2,0x07,0x46,0xa5,0x02,0x69,0xe6,0xa9,0xd3,0x30,0xba,0xd6,0x84,
0x63,0x13,0x1b,0xb2,0x1d,0xaf,0x36,0x8e,0xb7,0x53,0x05,0xbb,0x12,0x78,0x8f,0xbe,
0x71,0xbf,0xe4,0x1e,0x9e,0xa4,0xe5,0x2f,0x9b,0x31,0x67,0x4b,0xcb,0x43,0xc3,0xce,
0x44,0x3c,0x0f,0xd2,0xaa,0xd4,0xed,0xa7,0x7b,0x18,0xd0,0xda,0x0e,0x54,0xf1,0xde,
0xdf,0xa8,0x3f,0xe2,0x6d,0xcc,0xf8,0x70,0xe7,0x61,0xe9,0x85,0x65,0x2c,0x39,0xee,
0x60,0x81,0x89,0xc2,0xf3,0xf4,0xf5,0x8a,0x5c,0x5e,0xd9,0x4f,0x9f,0xb1,0xfd,0xfe
};
void convert(unsigned char *table,FILE *ifp,FILE *ofp)
{
unsigned char rb[16],wb[16];
unsigned int read_cnt;
int i;
do {
read_cnt = fread(rb,1,16,ifp);
if (read_cnt == 0) break;
for (i = 0;i < read_cnt;i++) {
wb[i] = table[rb[i]];
}
fwrite(wb,1,read_cnt,ofp);
} while (1);
}
int main(int argc, char* argv[])
{
FILE *ifp,*ofp;
if (argc != 4) {
printf("Encode\nendecsh -e source-file dest-file\nDecode\nendecsh -d source-file dest-file\n");
return 0;
}
ifp = fopen(argv[2],"rb");
if (ifp == NULL) {
printf("%s file not found.\n",argv[2]);
return 0;
}
ofp = fopen(argv[3],"wb");
if (ofp == NULL) {
fclose(ifp);
printf("Can't open %s file.\n",argv[3]);
return 0;
}
if (strcmp(argv[1],"-e") == 0 || strcmp(argv[1],"-E") == 0) {
printf("Encode...");
convert(enctable,ifp,ofp);
printf("OK.\n");
} else if (strcmp(argv[1],"-d") == 0 || strcmp(argv[1],"-D") == 0) {
printf("Decode...");
convert(dectable,ifp,ofp);
printf("OK.\n");
} else {
printf("unknown option '%s'\n",argv[1]);
}
fclose(ifp);
fclose(ofp);
return 0;
}