forked from VarunRajPanigrahy/CppCodes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessage encrypt.cpp
More file actions
64 lines (53 loc) · 1.67 KB
/
Message encrypt.cpp
File metadata and controls
64 lines (53 loc) · 1.67 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
// Program to encrypt messages given as input by rolling each character in a given number of characters
#include <iostream>
#include <string>
using namespace std;
void *charencode(int k, string character)
{
int n;
cout<<character<<endl<<endl;
n = character.length();
string copy;
for(int i = 0; i<=n; i++)
{
if(isalpha(character[i])) //checking whether it is alphabet
{
if(islower(character[i])) // checking whether it is an upper or lower case alphabet
{
if((character[i]+k)>=122) //if the ASCII value goes beyond the lower case alphabet range
copy[i] = char((character[i]+k)-122+96);
else
copy[i] = char(character[i]+k);
}
else
if((character[i]+k)>=90)//if the ASCII value goes beyond the upper case alphabet range
copy[i] = char((character[i]+k)-90+66);
else
copy[i] = char(character[i]+k);
}
else
copy[i] = character[i];
}
printf("%s\n",copy.c_str());
cout<<copy<<endl;
return 0;
}
int main()
{
int no_of_characters, no_of_testcases, char_increment;
cout<<"enter the no of test cases\n";
cin>>no_of_testcases;
for(int i =0; i<no_of_testcases; i++)
{
cout<<"Enter the no of characters\n";
cin>>no_of_characters;
string ch;
cout<<"enter the the increment in characters\n";
cin>>char_increment;
char_increment%=26;
cout<<"Enter the message\n";
cin.ignore(1);
getline(cin,ch,'\n');
charencode(char_increment,ch);
}
}