Encryption/Decription.

Hi guys, i'm supposed to complete an assignment to get the following : btw, IET = initial encrypted text while FET is final encrypted text. Appreciate your help please.
Please enter a 4 digit key : 1234

Please enter a plain text : S
Plaintext : S IET : T FET : p

Please enter a plain text : P
plaintext : P IET : T FET p


Please enter a plain text : _
plaintext : _ IET :h :FET L

each key has to be squared. for example 4 =16, 3=9, and so on and so forth to get the FET.

This is what i've done so far. My group's name is SP_MS6508 and the IET is TTh]T:>@9
And the FET shold be ppLyp▲>@↔

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
char shuffle(char i);
int main()
{
int i;
int j;
int o;
int w,x,y,z;
string groupname;
char IET[13];
char FET[13];

j=0;
cout<<"Please enter your 4 digit code code"<<endl;
cin>>o;
w=(o/1000);
x=(o-w*1000)/100;
y=(o-w*1000-x*100)/10;
z=(o-w*1000-x*100-y*10);
cout<<"please enter your group name"<<endl;
cin>>groupname;
i=groupname.length();
for(int j=0; j<i; j++)
{
if(j%4==0)
{

cout<<"Plaintext Character:"<<groupname[j]<<endl;
IET[j]=groupname[j]+(w*w);
cout<<fixed<<setw(20)<<left;
cout<<"IET Character:";
cout<<setw(20)<<IET[j];
FET[j]=(IET[j]);
cout<<setw(20)<<"FET character:"<<FET[j]<<endl;
}
else if(j%4==1)

{
cout<<"Plaintext Character:"<<groupname[j]<<endl;
IET[j]=groupname[j]+(x*x);
cout<<setw(20);
cout<<"IET Character:";
cout<<setw(20)<<IET[j];
FET[j]=x&&(IET[j]);
cout<<setw(20)<<"FET character:"<<FET[j]<<endl;
}
else if(j%4==2)

{
cout<<"Plaintext Character:"<<groupname[j]<<endl;
IET[j]=groupname[j]+(y*y);
cout<<setw(20);
cout<<"IET Character:";
cout<<setw(20)<<IET[j];
FET[j]=shuffle(IET[j]);
cout<<setw(20)<<"FET character:"<<FET[j]<<endl;
}
else if(j%4==3)

{ //key is = o
cout<<"Plaintext Character:"<<groupname[j]<<endl;
IET[j]=groupname[j]+(z*z);
cout<<setw(20);
cout<<"IET Character:";
cout<<setw(20)<<IET[j];
FET[j]=shuffle(IET[j]);
cout<<setw(20)<<"FET character:"<<FET[j]<<endl;
}
cout<<endl;
}


cout<<setw(40);
cout<<"Your key is"<<o<<endl;
cout<<setw(40);
cout<<"Your group name is ";
for(j=0; j<i; j++)
cout<<groupname[j];
cout<<endl;
cout<<setw(40);
cout<<"The initial encrypted text is ";
for(j=0; j<i; j++)
cout<<IET[j];
cout<<endl;
cout<<setw(40);
cout<<"Your final encrypted text is ";
for(j=0; j<i; j++)
cout<<FET[j];
cout<<endl;
system("pause");
return 0;
}
char shuffle(char i)
{
#define Mask0 0x01
#define Mask1 0x02
#define Mask2 0x04
#define Mask3 0x08
#define Mask4 0x10
#define Mask5 0x20
#define Mask6 0x40
#define Mask7 0x80
char x0, x1, x2, x3, x4, x5, x6, x7;
x0=( i & Mask0 ) >>6;
x1=( i & Mask1 ) >>4;
x2=( i & Mask2 ) <<1;
x3=( i & Mask3 ) <<3;
x4=( i & Mask4 ) >>3;
x5=( i & Mask5 ) <<2;
x6=( i & Mask6 ) <<2;
x7=( i & Mask7 ) <<5;
i=x0|x1|x2|x3|x4|x5|x6|x7;
return i;
}
Last edited on
Topic archived. No new replies allowed.