1,14 → 1,14 |
/* Copyright (C) 2019-2020 Logaev Maxim (turbocat2001), GPLv3 */ |
|
/* Author: turbocat2001*/ |
|
#include <stdio.h> |
#include "tea.c" |
#include <string.h> |
#include <stdint.h> |
#include <stdlib.h> |
#include "lang_en.c" |
#include <conio.h> |
|
#include "lang_en.c" |
#include "tea.c" |
|
#define ENCRYPT 1 |
#define DECRYPT 2 |
|
28,12 → 28,9 |
fseek(file, 0, SEEK_END); |
long size = ftell(file); |
fseek(file, 0, SEEK_SET); |
if(size%8==0) |
{ |
if(size%8==0) { |
return size; |
} |
else |
{ |
}else{ |
return (size/8+1)*8; |
} |
} |
42,8 → 39,7 |
{ |
FILE *input, *output; |
|
if((input = fopen(in_file,"rb"))==NULL) |
{ |
if((input = fopen(in_file,"rb"))==NULL){ |
printf(FILE_NOT_FOUND, in_file); |
exit(1); |
} |
55,14 → 51,12 |
size_diff=(uint8_t)(size_f-size_orig_file(input)); |
uint32_t *buff; |
buff=malloc(size_f); |
if(!buff) |
{ |
if(!buff) { |
puts(MEMORY_ERROR); |
exit(-1); |
} |
|
if(arg==ENCRYPT) |
{ |
if(arg==ENCRYPT){ |
printf(LOAD_IN_RAM,in_file); |
fread(buff, 1,size_f, input); |
printf(FILE_ENCRYPTION); |
81,8 → 75,7 |
exit(0); |
} |
|
else if(arg==DECRYPT) |
{ |
else if(arg==DECRYPT){ |
long size_f=size_orig_file(input); |
printf(LOAD_IN_RAM,in_file); |
fread(&size_diff,1,1,input); |
108,8 → 101,7 |
uint32_t temp_block[2]; |
FILE *input, *output; |
|
if((input = fopen(in_file,"rb"))==NULL) |
{ |
if((input = fopen(in_file,"rb"))==NULL){ |
printf(FILE_NOT_FOUND, in_file); |
exit(1); |
} |
148,19 → 140,15 |
fread(temp_block, sizeof(uint32_t), 2, input); |
TEA_decrypt(temp_block,key); |
|
if(size_f>=8) |
{ |
if(size_f>=8){ |
fwrite(temp_block,sizeof(uint32_t),2,output); |
} |
else |
{ |
}else{ |
fwrite(temp_block,1,size_f,output); |
} |
|
size_f=size_f-8; |
|
if(size_f<0) |
{ |
if(size_f<0){ |
size_f=0; |
} |
} |
195,8 → 183,7 |
char hex[]={"abcdefABCDEF0123456789"}; |
for(int i=0; i<32; i++) |
{ |
if(strchr(hex,str[i])!=NULL) |
{ |
if(strchr(hex,str[i])!=NULL){ |
count++; |
} |
} |
210,16 → 197,11 |
char str_key[4][9]; |
if(valid_key(str)&&(strlen(str)==32)) |
{ |
for(int i=0; i<4; i++) |
{ |
for(int i=0; i<4; i++){ |
str_to_strkey(str, str_key); |
key[i]=(uint32_t)strtol(str_key[i],NULL,16); |
} |
|
} |
|
else |
{ |
}else{ |
printf(INVALID_KEY_FORMAT); |
exit(-1); |
} |
228,22 → 210,17 |
void key_file_read(char *key_file) |
{ |
FILE *keyfile; |
if((keyfile = fopen(key_file,"rb"))==NULL) |
{ |
if((keyfile = fopen(key_file,"rb"))==NULL){ |
printf(FILE_NOT_FOUND, key_file); |
exit(-1); |
} |
|
if(size_orig_file(keyfile)==16) |
{ |
if(size_orig_file(keyfile)==16) { |
fread(key,sizeof(uint32_t),4, keyfile); |
} |
else |
{ |
}else{ |
printf(INVALID_KEY_FORMAT); |
exit(-1); |
} |
|
fclose(keyfile); |
} |
|
253,14 → 230,12 |
char found=0; |
for(int j=3; j<argc; j++) |
{ |
if(!strcmp(argv[j],"-k")) |
{ |
if(!strcmp(argv[j],"-k")){ |
found=1; |
key_con_read(argv[j+1]); |
break; |
} |
else if(!strcmp(argv[j],"-K")) |
{ |
else if(!strcmp(argv[j],"-K")){ |
found=1; |
key_file_read(argv[j+1]); |
break; |
267,13 → 242,11 |
} |
} |
|
if(!found) |
{ |
if(!found){ |
printf(NO_KEY_OR_KEYFILE); |
exit(-1); |
} |
|
|
for(int i=3;i<argc; i++){ |
if(!strcmp(argv[i],"-e")) |
{ |
293,8 → 266,7 |
void key_write_in_file(char *keyfilename) |
{ |
FILE *keyfile; |
if((keyfile = fopen(strcat(keyfilename, ".key"), "wb"))==NULL) |
{ |
if((keyfile = fopen(strcat(keyfilename, ".key"), "wb"))==NULL){ |
printf(INCORRECT_FILE, keyfilename); |
exit(-1); |
} |
302,44 → 274,30 |
printf(KEY_RECORD_IN_FILE, keyfilename); |
fclose(keyfile); |
exit(0); |
|
} |
|
|
int main(int argc, char **argv) |
{ |
con_init_console_dll(); |
con_set_title("TEAtool\0"); |
if(argc==7) |
{ |
if(argc==7){ |
findopt(argc,argv, argv[1],argv[2]); |
} |
else if(argc==2 && !strcmp(argv[1],"-a")) |
{ |
else if(argc==2 && !strcmp(argv[1],"-a")){ |
show_about(); |
exit(0); |
} |
|
else if(argc==2 && !strcmp(argv[1],"-h")) |
{ |
else if(argc==2 && !strcmp(argv[1],"-h")){ |
show_help(); |
exit(0); |
} |
|
else if(argc==4 && !strcmp(argv[1],"-r")) |
{ |
else if(argc==4 && !strcmp(argv[1],"-r")){ |
key_con_read(argv[2]); |
key_write_in_file(argv[3]); |
} |
|
|
else |
{ |
else{ |
printf(INVALID_ARG); |
exit(0); |
} |
|
return 0; |
|
} |
|