Implement decrypt

This commit is contained in:
Stefan `Sec` Zehl 2011-06-27 00:58:24 +02:00
parent 9a7c622240
commit 9e575219fd
1 changed files with 9 additions and 3 deletions

View File

@ -35,6 +35,7 @@ int main(int argc, char *argv[]) {
k[0]=0; k[1]=0; k[2]=0; k[3]=0; k[0]=0; k[1]=0; k[2]=0; k[3]=0;
char block=16; char block=16;
char *outfile=NULL; // outfile == infile char *outfile=NULL; // outfile == infile
int decrypt=0;
/* init section */ /* init section */
prog=argv[0]; prog=argv[0];
@ -45,12 +46,16 @@ int main(int argc, char *argv[]) {
} }
/* The big getopt loop */ /* The big getopt loop */
while ((c = getopt(argc, argv, "vhk:b:o:")) != EOF) while ((c = getopt(argc, argv, "vhdk:b:o:")) != EOF)
switch (c) { switch (c) {
case 'v': case 'v':
verbose++; verbose++;
break; break;
case 'd':
decrypt=1;
break;
case 'k': case 'k':
hexkey(optarg, k); hexkey(optarg, k);
break; break;
@ -69,8 +74,9 @@ int main(int argc, char *argv[]) {
"This program en/decrypts a file with the XXTEA algorithm\n" "This program en/decrypts a file with the XXTEA algorithm\n"
"\n\n" "\n\n"
"-v Be verbose (-v -v = even more)\n" "-v Be verbose (-v -v = even more)\n"
"-d Decrypt (instead of encrypt)\n"
"-o file Output to <file>. (Default: overwrite input file)\n" "-o file Output to <file>. (Default: overwrite input file)\n"
"-k key 128bit hex key. [Not yet implemented]\n" "-k key 128bit hex key.\n"
"-b block Set blocksize. (Default: file size)\n" "-b block Set blocksize. (Default: file size)\n"
"-h This help\n\n" "-h This help\n\n"
"\n",prog); "\n",prog);
@ -134,7 +140,7 @@ int main(int argc, char *argv[]) {
fprintf(stderr,"Whoops. needs padding: cnt=%d, mod=%d\n",cnt,cnt%sizeof(*buf)); fprintf(stderr,"Whoops. needs padding: cnt=%d, mod=%d\n",cnt,cnt%sizeof(*buf));
}; */ }; */
btea(buf, cnt, k); btea(buf, decrypt?-cnt:cnt, k);
if(!outfile) // in-place crypting... if(!outfile) // in-place crypting...
if (fseek(fp,-cnt*sizeof(*buf),SEEK_CUR) != 0){ if (fseek(fp,-cnt*sizeof(*buf),SEEK_CUR) != 0){