-
Notifications
You must be signed in to change notification settings - Fork 0
/
cipher.c
46 lines (37 loc) · 930 Bytes
/
cipher.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
45
46
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char * cipher(char * input) {
for (int i = 0; i < strlen(input); i++) {
if (input[i] == ' ') {
continue;
}
int thechar = (int) input[i];
if (thechar >= 65 && thechar <= 90) {
thechar += 13;
if (thechar > 90) {
thechar -= 26;
}
} else if (thechar >= 97 && thechar <= 122) {
thechar += 13;
if (thechar > 122) {
thechar -= 26;
}
}
input[i] = (char) thechar;
}
return input;
}
int main(int argc, char ** argv) {
if (argc <= 1) {
printf("usage: cipher [message]\n");
return 0;
}
char * output = malloc(sizeof(char) * 256);
int i;
for (i = 1; i < argc; i++) {
output = cipher(argv[i]);
printf("%s\n", output);
}
return 0;
}