]> git.za3k.com Git - cryptopals.git/commitdiff
Partial progress master
authorZachary Vance <za3k@za3k.com>
Fri, 26 May 2017 02:28:14 +0000 (19:28 -0700)
committerZachary Vance <za3k@za3k.com>
Fri, 26 May 2017 02:28:14 +0000 (19:28 -0700)
io.c
set1p7.test.c [new file with mode: 0644]

diff --git a/io.c b/io.c
index 8b59d2dd469b61d2ccf1e86db327784040c31ce1..47eb78184210b68aadeaea3ec9079be0b22deecd 100644 (file)
--- 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 (file)
index 0000000..3cc662e
--- /dev/null
@@ -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.
+}