From: Zachary Vance Date: Fri, 26 May 2017 02:28:14 +0000 (-0700) Subject: Partial progress X-Git-Url: https://git.za3k.com/?a=commitdiff_plain;h=HEAD;p=cryptopals.git Partial progress --- diff --git a/io.c b/io.c index 8b59d2d..47eb781 100644 --- a/io.c +++ b/io.c @@ -145,9 +145,8 @@ void print_buffer(char* buffer, int length) { free(output); } -int read_base64_file(char* path, char** ciphertext, int *ciphertext_length) { - char* ciphertext_base64=NULL; - int ciphertext_base64_length=0; +void gulp_file_strip_newlines(char* path, char** result_text, int *result_length) { + *result_length=0; FILE *f = fopen(path, "r"); int line_length=0; int line_buf_length; @@ -155,13 +154,20 @@ int read_base64_file(char* path, char** ciphertext, int *ciphertext_length) { while ((line_length = getline(&line, &line_buf_length, f))>0) { if (line[line_length-1] == '\000') line_length--; if (line[line_length-1] == '\n') line_length--; - ciphertext_base64 = realloc(ciphertext_base64, ciphertext_base64_length+line_length+1); - memcpy(ciphertext_base64+ciphertext_base64_length, line, line_length); - ciphertext_base64_length += line_length; + *result_text = realloc(*result_text, (*result_length)+line_length+1); + memcpy((*result_text)+(*result_length), line, line_length); + (result_length) += line_length; } free(line); fclose(f); - ciphertext_base64[ciphertext_base64_length]=0; + (*result_text)[*result_length]=0; + (*result_length)++; +} + +int read_base64_file(char* path, char** ciphertext, int *ciphertext_length) { + char* ciphertext_base64=NULL; + int ciphertext_base64_length=0; + gulp_file_strip_newlines(path, &ciphertext_base64, &ciphertext_base64_length); int succ = decode_base64(ciphertext_base64, *ciphertext, ciphertext_length); free(ciphertext_base64); return succ; diff --git a/set1p7.test.c b/set1p7.test.c new file mode 100644 index 0000000..3cc662e --- /dev/null +++ b/set1p7.test.c @@ -0,0 +1,9 @@ +//AES in ECB mode + +int main() { + char *key = "YELLOW SUBMARINE"; + char *encrypted_path = "problems/set-1/7.txt"; + + // Decrypt the file + //Easiest way: use OpenSSL::Cipher and give it AES-128-ECB as the cipher. +}