From 08e8e444b3115841e9084212b718e94ecda3604b Mon Sep 17 00:00:00 2001 From: jciberlin Date: Sat, 29 Jun 2024 15:22:54 +0200 Subject: [PATCH] vernam_cipher: Use initialization instead of declaration and assignment - vernam_cipher: Use initialization instead of declaration and assignment for local variables --- Src/crypto/vernam_cipher.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/Src/crypto/vernam_cipher.c b/Src/crypto/vernam_cipher.c index 5137c8e..71edb76 100644 --- a/Src/crypto/vernam_cipher.c +++ b/Src/crypto/vernam_cipher.c @@ -49,18 +49,14 @@ VernamCipher_encrypt(char* msg, const char* key, int32_t key_length) { if ((int32_t)msg_length == key_length) { for (int32_t i = 0; i < key_length; ++i) { if (Utils_isAlpha(msg[i])) { - int8_t c; + int8_t c = UPPER_A_ASCII; if (Utils_isLowerChar(key[i])) { c = LOWER_A_ASCII; - } else { - c = UPPER_A_ASCII; } - int32_t ascii_val; + int32_t ascii_val = LOWER_A_ASCII; if (Utils_isUpperChar(msg[i])) { ascii_val = UPPER_A_ASCII; - } else { - ascii_val = LOWER_A_ASCII; } int32_t temp = (((int8_t)msg[i] - ascii_val + (int8_t)key[i] - c) % NUM_OF_ALPHA); @@ -80,18 +76,14 @@ VernamCipher_decrypt(char* msg, const char* key, int32_t key_length) { if ((int32_t)msg_length == key_length) { for (int32_t i = 0; i < key_length; ++i) { if (Utils_isAlpha(msg[i])) { - int8_t c; + int8_t c = UPPER_A_ASCII; if (Utils_isLowerChar(key[i])) { c = LOWER_A_ASCII; - } else { - c = UPPER_A_ASCII; } - int32_t ascii_val; + int32_t ascii_val = LOWER_A_ASCII; if (Utils_isUpperChar(msg[i])) { ascii_val = UPPER_A_ASCII; - } else { - ascii_val = LOWER_A_ASCII; } int32_t cipher = ((msg[i] - ascii_val) - (key[i] - c));