forked from legendary-acp/Basic_programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcipher.cpp
More file actions
66 lines (55 loc) · 969 Bytes
/
cipher.cpp
File metadata and controls
66 lines (55 loc) · 969 Bytes
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
#include<stdio.h>
#include<string.h>
int main()
{ int n,k,r,m,a[1000];
char ch[1000];
printf("enter any string\n");
scanf("%s",ch);
printf("enter number of characters it should increase for every element\n");
scanf("%d",&n);
k=sizeof(ch);
for(int i=0;ch[i]!='\0';i++)
{ if(ch[i]>='a'&&ch[i]<='z')
{ r=n%26;
m=ch[i];
if(m+r>122)
{ a[i]=m+r-123;
ch[i]=a[i];
ch[i]=ch[i]+'a';
printf("%c",ch[i]);
}
else
{ m=ch[i]+r;
ch[i]=m;
printf("%c",ch[i]);
}
}
else if(ch[i]>='A'&&ch[i]<='Z')
{ r=n%26;
ch[i]=ch[i]+r;
if(ch[i]>'Z')
{
ch[i]=ch[i]-'Z'+'A';
a[i]=ch[i]-1;
ch[i]=a[i];
printf("%c",ch[i]);}
else
printf("%c",ch[i]);
}
else if(ch[i]>='0'&&ch[i]<='9')
{ r=n%10;
ch[i]=ch[i]+r;
if(ch[i]>'9')
{
ch[i]=ch[i]-'9'+'0';
a[i]=ch[i]-1;
ch[i]=a[i];
printf("%c",ch[i]);}
else
printf("%c",ch[i]);
}
else
printf("%c",ch[i]);
}
return 0;
}