#include #include #include #include #include #include #include void usage(char *); int main(int argc, char *argv[]){ int fdin, fdout; int strlen, i, c; int cryptFlag=0, decryptFlag=0,seekFlag=0; int seekOffset=50688; char *infile=NULL, *outfile=NULL; char inbuff[8192]; char outbuff[8192]; while ((c = getopt(argc, argv, "cdhi:o:s:")) != EOF){ switch (c) { case 'c': cryptFlag++; break; case 'd': decryptFlag++; break; case 'i': infile = optarg; break; case 'o': outfile = optarg; break; case 's': seekOffset = atoi(optarg); break; case 'h': usage(argv[0]); break; default: usage(argv[0]); break; } } if ((cryptFlag && decryptFlag) || (!cryptFlag && !decryptFlag)){ printf("Must specify either -c or -d but not both\n"); usage(argv[0]); } if (infile){ fdin = open(infile, O_RDONLY); if (fdin == -1){ perror("open infile"); } } else { fdin = STDIN_FILENO; } if (outfile){ fdout = open(outfile, O_WRONLY|O_CREAT|O_EXCL, 0644); if (fdout == -1){ perror("open outfiel"); } } else { fdout = STDOUT_FILENO; } memset(inbuff, '\0', sizeof(inbuff)); memset(outbuff, '\0', sizeof(outbuff)); if (decryptFlag) lseek(fdin, seekOffset, SEEK_SET); while ((strlen = read(fdin, inbuff, sizeof(inbuff))) != 0){ for (i=0; i < strlen ; i++){ if (cryptFlag){ if (!(i % 2)) outbuff[i] = (inbuff[i] + 0x44) & 0xff; else outbuff[i] = (inbuff[i] + 0x63) & 0xff; } else { if (!(i % 2)) outbuff[i] = inbuff[i] - 0x44; else outbuff[i] = inbuff[i] - 0x63; } } write(fdout, outbuff, strlen); } close(fdin); close(fdout); return(0); } void usage(char *progname){ char *c; c = strrchr(progname, '/'); if (c) c++; else c = progname; printf("Usage: %s -cd[h] [-i infile] [-o outfile] [-s seek] \n", c); printf(" Shell-lock {en,de}coder by mudge@l0pht.com and _lumpy\n"); printf(" -c encrypt\n"); printf(" -d decrypt\n"); printf(" -h help\n"); printf(" -i input file\n"); printf(" -o output file\n"); printf(" -s seed offset [defaults to 50688]\n"); exit(1); }