In: Computer Science
Project Description:
In groups of four students, implement (New Encryption Algorithm)
character oriented and apply it using any programming Language that
you are familiar with to encrypt and decrypt your name.
Your work should cover:
1. Create the algorithm and explain
(encryption-decryption) using block diagram.
2. Mention whether will you use the keys or not in
your algorithm.
3- If you will use keys, explain how to generate
the keys.
2. Display the generated keys
3. Encrypt your name
4. Display the plain text
5. Display the cipher text
6. Decrypt the cipher text to get the
plaintext.
#include <iostream>
#include <stdlib.h>
#include <ctime>
using namespace std;
// This function receives text and shift and
// returns the encrypted text
string encrypt(string text, int s)
{
string result = "";
// traverse text
for (int i=0;i<text.length();i++)
{
// apply transformation to each character
// Encrypt Uppercase letters
if (isupper(text[i]))
result += char(int(text[i]+s-65)%26 +65); //Calculate:
Y = (X + K) % 26
(step 2 in algorithm)
// Encrypt Lowercase letters
else
result += char(int(text[i]+s-97)%26 +97); //Calculate:
Y = (X + K) % 26
(step 2 in algorithm)
}
// Return the resulting string
return result;
}
// This function receives text and shift and
// returns the decrypted text
string decrypt(string text, int s)
{
string result = "";
// traverse text
for (int i=0;i<text.length();i++)
{
// apply transformation to each character
// decrypt Uppercase letters
if (isupper(text[i]))
result += char(int(text[i]-s-65)%26 +65); //Calculate:
Y = (X - K) % 26
(step 2 in algorithm)
// Encrypt Lowercase letters
else
result += char(int(text[i]-s-97)%26 +97); //Calculate:
Y = (X - K) % 26
(step 2 in algorithm)
}
// Return the resulting string
return result;
}
// Driver program to test the above function
int main()
{
string text;
cout<<"Enter your Name :";
cin>>text;
cout << "Text : " << text;
int key;
srand((unsigned) time(0)); //To avoid the repetitive sequence, you
must set the seed as an argument to the srand() method.
key = rand() % 20+1; //
generate a random key in a range of 1 to 20
cout<<"\nKey ="<<key;
string cipherText = encrypt(text, key); // encrypt function is
called with randomly generated key
string plainText = decrypt(cipherText, key); // decrypt function is
called with previously randomly generated key
cout << "\nCipher Text: " << cipherText;
cout << "\nOriginal Text: " <<
plainText;
return 0;
}
algorithm of encryption
For every letter in the message M :
1. Convert the letter into the number that
matches its order in the alphabet starting from 0, and call this
number X.
( A=0, B=1, C=2, ...,Y=24, Z=25)
2. Calculate: Y = (X + K) % 26
3. Convert the number Y into a letter that matches its order in the alphabet starting from 0.
algorithm of decryption
For every letter in the message M :
1. Convert the letter into the number that
matches its order in the alphabet starting from 0, and call this
number X.
( A=0, B=1, C=2, ...,Y=24, Z=25)
2. Calculate: Y = (X - K) % 26
3. Convert the number Y into a letter that matches its order in the alphabet starting from 0.
Main Function encrypt function
decrypt function