-
Notifications
You must be signed in to change notification settings - Fork 0
/
caesar.c
44 lines (37 loc) · 881 Bytes
/
caesar.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// Created by Jakub Josef Forman on 17.09.2024.
//
#include <ctype.h>
#include "caesar.h"
void encrypt(char text[], int shift) {
char ch;
int i = 0;
while (text[i] != '\0') {
ch = text[i];
if (ch >= 'A' && ch <= 'Z') {
// if (ch >= 65 && ch <= 90) {
ch = (ch - 'A' + shift) % 26 + 'A';
}
if (islower(ch)) {
ch = (ch - 'a' + shift) % 26 + 'a';
}
text[i] = ch;
i++;
}
}
void decrypt(char text[], int shift) {
char ch;
int i = 0;
while (text[i] != '\0') {
ch = text[i];
if (ch >= 'A' && ch <= 'Z') {
// if (ch >= 65 && ch <= 90) {
ch = (ch - 'A' - shift + 26) % 26 + 'A';
}
if (islower(ch)) {
ch = (ch - 'a' - shift + 26) % 26 + 'a';
}
text[i] = ch;
i++;
}
}