-
Notifications
You must be signed in to change notification settings - Fork 5
/
Crypt.c
54 lines (51 loc) · 1.19 KB
/
Crypt.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
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <string.h>
void encrypt(char *msg, int pass) {
for (int i = 0; i < strlen(msg); i++) {
msg[i] = (msg[i] + pass) % 256;
}
printf("\n-----------------------------\n");
printf("Encrypted message: ");
for (int i = 0; i < strlen(msg); i++) {
printf("%c", msg[i]);
}
printf("\n");
}
void decrypt(char *msg, int pass) {
for (int i = 0; i < strlen(msg); i++) {
msg[i] = (msg[i] - pass + 256) % 256;
}
printf("\n-----------------------------\n");
printf("Decrypted message: ");
for (int i = 0; i < strlen(msg); i++) {
printf("%c", msg[i]);
}
printf("\n");
}
int main() {
int choice, pass;
char msg[100];
printf(" 1. ENCRYPT \n 2. DECRYPT \n");
printf("Enter your choice : ");
scanf("%d", &choice);
printf("\n-----------------------------\n");
switch (choice) {
case 1:
printf("Enter the message to Encrypt : ");
scanf("%s", msg);
printf("Enter your password (+ve integer): ");
scanf("%d", &pass);
encrypt(msg, pass);
break;
case 2:
printf("Enter the message to Decrypt : ");
scanf("%s", msg);
printf("Enter your password (+ve integer): ");
scanf("%d", &pass);
decrypt(msg, pass);
break;
default:
printf("Invalid choice\n");
break;
}
}