Skip to content

Commit 08e8e44

Browse files
jciberlinIgor-Misic
authored andcommitted
vernam_cipher: Use initialization instead of declaration and assignment
- vernam_cipher: Use initialization instead of declaration and assignment for local variables
1 parent 49c13a5 commit 08e8e44

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

Src/crypto/vernam_cipher.c

+4-12
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,14 @@ VernamCipher_encrypt(char* msg, const char* key, int32_t key_length) {
4949
if ((int32_t)msg_length == key_length) {
5050
for (int32_t i = 0; i < key_length; ++i) {
5151
if (Utils_isAlpha(msg[i])) {
52-
int8_t c;
52+
int8_t c = UPPER_A_ASCII;
5353
if (Utils_isLowerChar(key[i])) {
5454
c = LOWER_A_ASCII;
55-
} else {
56-
c = UPPER_A_ASCII;
5755
}
5856

59-
int32_t ascii_val;
57+
int32_t ascii_val = LOWER_A_ASCII;
6058
if (Utils_isUpperChar(msg[i])) {
6159
ascii_val = UPPER_A_ASCII;
62-
} else {
63-
ascii_val = LOWER_A_ASCII;
6460
}
6561

6662
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) {
8076
if ((int32_t)msg_length == key_length) {
8177
for (int32_t i = 0; i < key_length; ++i) {
8278
if (Utils_isAlpha(msg[i])) {
83-
int8_t c;
79+
int8_t c = UPPER_A_ASCII;
8480
if (Utils_isLowerChar(key[i])) {
8581
c = LOWER_A_ASCII;
86-
} else {
87-
c = UPPER_A_ASCII;
8882
}
8983

90-
int32_t ascii_val;
84+
int32_t ascii_val = LOWER_A_ASCII;
9185
if (Utils_isUpperChar(msg[i])) {
9286
ascii_val = UPPER_A_ASCII;
93-
} else {
94-
ascii_val = LOWER_A_ASCII;
9587
}
9688

9789
int32_t cipher = ((msg[i] - ascii_val) - (key[i] - c));

0 commit comments

Comments
 (0)