Skip to content

Commit

Permalink
caesar_cipher: Use initialization instead of declaration and assignment
Browse files Browse the repository at this point in the history
- caesar_cipher - Use initialization instead of declaration and assignment for local variables
  • Loading branch information
jciberlin authored and Igor-Misic committed Jun 29, 2024
1 parent ebce6c6 commit 49c13a5
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions Src/crypto/caesar_cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ CaesarCipher_encrypt(char* msg, uint8_t shift) {
const size_t length = strlen(msg);
for (size_t i = 0U; i < length; ++i) {
if (Utils_isAlpha(msg[i])) {
uint8_t encrypted_char;
uint8_t ascii_val = LOWER_A_ASCII;
if (Utils_isUpperChar(msg[i])) {
encrypted_char = (((uint8_t)msg[i] + shift - UPPER_A_ASCII) % MAX_SHIFT) + UPPER_A_ASCII;
} else {
encrypted_char = (((uint8_t)msg[i] + shift - LOWER_A_ASCII) % MAX_SHIFT) + LOWER_A_ASCII;
ascii_val = UPPER_A_ASCII;
}
uint8_t encrypted_char = (((uint8_t)msg[i] + shift - ascii_val) % MAX_SHIFT) + ascii_val;
msg[i] = (char)encrypted_char;
}
}
Expand All @@ -63,12 +62,11 @@ CaesarCipher_decrypt(char* msg, uint8_t shift) {
const size_t length = strlen(msg);
for (size_t i = 0U; i < length; ++i) {
if (Utils_isAlpha(msg[i])) {
uint8_t decrypted_char;
uint8_t ascii_val = LOWER_A_ASCII;
if (Utils_isUpperChar(msg[i])) {
decrypted_char = (((uint8_t)msg[i] - shift - UPPER_A_ASCII) % MAX_SHIFT) + UPPER_A_ASCII;
} else {
decrypted_char = (((uint8_t)msg[i] - shift - LOWER_A_ASCII) % MAX_SHIFT) + LOWER_A_ASCII;
ascii_val = UPPER_A_ASCII;
}
uint8_t decrypted_char = (((uint8_t)msg[i] - shift - ascii_val) % MAX_SHIFT) + ascii_val;
msg[i] = (char)decrypted_char;
}
}
Expand Down

0 comments on commit 49c13a5

Please sign in to comment.