cryptopals_c

cryptopals crypto challenges solutions in pure c
git clone git://git.superpozycja.net/cryptopals_c
Log | Files | Refs | README

commit 772a79bfbb99aa54f35b41d118375f9a153cfb63
parent 21ed72c1e14495d5f0b7dd49e603560cccc57fd8
Author: superpozycja <anna@superpozycja.net>
Date:   Sat, 22 Feb 2025 19:21:23 +0100

cleanup commit

Diffstat:
M.gitignore | 1+
Mdata/1_4.txt | 3+--
Mlib/analysis.c | 1+
Msrc/s1/c6.c | 6+++---
Msrc/s1/c7.c | 37++-----------------------------------
5 files changed, 8 insertions(+), 40 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,2 +1,3 @@ *.swp bin +tags diff --git a/data/1_4.txt b/data/1_4.txt @@ -324,4 +324,4 @@ e03555453d1e31775f37331823164c341c09e310463438481019fb0b12fa 1c595d183539220eec123478535337110424f90a355af44c267be848173f 41053f5cef5f6f56e4f5410a5407281600200b2649460a2e3a3c38492a0c 4c071a57e9356ee415103c5c53e254063f2019340969e30a2e381d5b2555 -32042f46431d2c44607934ed180c1028136a5f2b26092e3b2c4e2930585a -\ No newline at end of file +32042f46431d2c44607934ed180c1028136a5f2b26092e3b2c4e2930585a diff --git a/lib/analysis.c b/lib/analysis.c @@ -100,6 +100,7 @@ static float get_i_c_m(ba *ct, unsigned int m) { float res; int i; + res = 0; for (i = 0; i < m; i++) { ba *chunk = (ba *) malloc(sizeof(ba)); diff --git a/src/s1/c6.c b/src/s1/c6.c @@ -15,7 +15,7 @@ void break_w_keylen(ba *ct, unsigned int m) chunk->len = ct->len / m; chunk->val = (uint8_t *) malloc(sizeof(uint8_t) * chunk->len); - + for (j = 0, k = 0; j <chunk->len && k + i < ct->len; j++, k += m) chunk->val[j] = ct->val[k + i]; @@ -51,8 +51,8 @@ int main(int argc, char *argv[]) } base64_to_hex(&hex, b64); - ct = ba_from_hex(hex); - + ct = ba_from_hex(hex); + int m = guess_vigenere_keylen(ct); break_w_keylen(ct, m); diff --git a/src/s1/c7.c b/src/s1/c7.c @@ -4,34 +4,6 @@ #include <ba.h> #include <util.h> -/* -int decrypt(unsigned char *ct, int ct_len, unsigned char *key, - unsigned char *pt) -{ - EVP_CIPHER_CTX *ctx; - int pt_len; - int len; - - if (!(ctx = EVP_CIPHER_CTX_new())) - return -1; - - if(EVP_DecryptInit_ex(ctx, EVP_aes_128_ecb(), NULL, key, NULL) != 1) - return -1; - - if(EVP_DecryptUpdate(ctx, pt, &len, ct, ct_len) != 1) - return -1; - - pt_len = len; - - if(EVP_DecryptFinal_ex(ctx, pt + len, &len) != 1) - return -1; - pt_len += len; - - EVP_CIPHER_CTX_free(ctx); - return pt_len; -} -*/ - int main(int argc, char *argv[]) { unsigned char *key = (unsigned char*) "YELLOW SUBMARINE"; @@ -55,11 +27,6 @@ int main(int argc, char *argv[]) } base64_to_hex(&hex, b64); - - pt = (char *) malloc(sizeof(char) * strlen(hex) + 1); - - //pt_len = decrypt(hex, strlen(hex), key, pt); - - /* Add a NULL terminator. We are expecting printable text */ - //pt[pt_len] = '\0'; + printf("%s\n", hex); + return 0; }