-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCaesarCypher.cpp
More file actions
88 lines (87 loc) · 1.31 KB
/
Copy pathCaesarCypher.cpp
File metadata and controls
88 lines (87 loc) · 1.31 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<stdio.h>
#include<strings.h>
#include<stdlib.h>
char a[100],x[100]="HELLO",y[100]="BYE",w[100];
int b,c,ch;
int encode();
int decode();
int main()
{
printf("\n---- PASSWORD ENCODER / DECODER ---\n\nEnter 1 to encode\nEnter 2 to Decode\nEnter 3 to exit\n\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1: encode();
break;
case 2: decode();
break;
case 3: printf("\n\nThanks for using :)\n");
return 1;
break;
default:printf("\n\nInvalid Input!\n\n");
}
main();
return 0;
}
int encode()
{
printf("Enter your Password: ");
scanf("%s",&a);
strcat(a,x);
strcat(y,a);
b=strlen(y);
printf("The Encoded password is: ");
for(c=0;c<b/2;c++)
{
if(c%2==0)
{
printf("%c",y[c]+7);
}
else
{
printf("%c",y[c]-4);
}
}
for(c=b/2;c<b;c++)
{
if(c%2==0)
{
printf("%c",y[c]+4);
}
else
{
printf("%c",y[c]-7);
}
}
return 0;
}
int decode()
{
printf("Enter Encoded password: ");
scanf("%s",&w);
b=strlen(w);
printf("Decoded Password: ");
for(c=3;c<b/2;c++)
{
if(c%2==0)
{
printf("%c",w[c]-7);
}
else
{
printf("%c",w[c]+4);
}
}
for(c=b/2;c<b-5;c++)
{
if(c%2==0)
{
printf("%c",w[c]-4);
}
else
{
printf("%c",w[c]+7);
}
}
return 0;
}