Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f775d44

Browse files
Merge pull request #91 from sgrG24/master
Added Two ciphers
2 parents 533d2b4 + 72fbbf4 commit f775d44

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//Atbash cipher
2+
#include<iostream>
3+
using namespace std;
4+
5+
//Function that convert the message.
6+
string atbash(string msg)
7+
{
8+
/*This function takes msg as input and
9+
map it to its reverse alphabatically order.*/
10+
11+
string cipher;
12+
for(int i=0;i<msg.length();i++)
13+
{
14+
if(msg[i]==' ')
15+
cipher= cipher + ' ';
16+
else if(msg[i]>='A' && msg[i]<='Z')
17+
cipher=cipher+(char)('Z'-(msg[i]-'A'));
18+
else
19+
cipher=cipher+(char)('z'-(msg[i]-'a'));
20+
}
21+
return cipher;
22+
}
23+
24+
//Main program.
25+
int main()
26+
{
27+
string text;
28+
cout<<"Enter the message to encrypt/decrypt---"<<endl;
29+
cin>>text;
30+
cout<<"Converted message---"<<endl<<atbash(text);
31+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## **Atbash Cipher**
2+
The [Atbash cipher](https://en.wikipedia.org/wiki/Atbash) is a monoalphabetic cipher formed by taking the alphabet and mapping it to its reverse, so that the first letter becomes the last letter, the second letter becomes the second to last letter, and so on.
3+
4+
5+
|**Plain** | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
6+
|-----------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
7+
|**Cipher** | Z | Y | X | W | V | U | T | S | R | Q | P | O | N | M | L | K | J | I | H | G | F | E | D | C | B | A |
8+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//C++ implemention of morse code generator
2+
#include<iostream>
3+
using namespace std;
4+
#include<map> //For map data structure
5+
6+
// Encryption Function
7+
void encryption(string msg)
8+
{
9+
// Decalaring map structure and Defination of map
10+
map<char, string> encrypt;
11+
encrypt['A']=".-";encrypt['B']="-..."; encrypt['C']="-.-."; encrypt['D']="-..";
12+
encrypt['E']=".";encrypt['F']="..-."; encrypt['G']="--."; encrypt['H']="....";
13+
encrypt['I']="..";encrypt['J']=".---"; encrypt['K']="-.-"; encrypt['L']=".-..";
14+
encrypt['M']="--";encrypt['N']="-."; encrypt['O']="---"; encrypt['P']=".--.";
15+
encrypt['Q']="--.-";encrypt['R']=".-."; encrypt['S']="..."; encrypt['T']="-";
16+
encrypt['U']="..-";encrypt['V']="...-"; encrypt['W']=".--"; encrypt['X']="-..-";
17+
encrypt['Y']="-.--";encrypt['Z']="--..";
18+
encrypt['1']=".----"; encrypt['2']="..---"; encrypt['3']="...--";encrypt['4']="....-";
19+
encrypt['5']="....."; encrypt['6']="-...."; encrypt['7']="--...";
20+
encrypt['8']="---.."; encrypt['9']="---."; encrypt['0']="-----";
21+
22+
string cipher;
23+
for(int i=0;i<msg.size();i++)
24+
{
25+
if(msg[i]!=' ')
26+
cipher = cipher + encrypt[msg[i]];
27+
else
28+
cipher = cipher + " ";
29+
}
30+
cout<<cipher;
31+
}
32+
//Driver program
33+
int main()
34+
{
35+
string key="CONVERT THIS INTO MORSE CODE";
36+
//Calling Function
37+
encryption(key);
38+
return 0;
39+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /