The below code is for a simple password encryption/decryption program. The code is working perfectly, but the only thing I want to know from you is if this is good logic.
PEND.h
#ifndef PEND_H
#define PEND_H
class PEND
{
private:
char UString[30];
char Password[70];
int key;
int raw;
int Rid;
public:
PEND();
void menu();
void Encryption();
void Decryption();
void WFile();
bool CheckID();
void about();
};
#endif // PEND_H
PEND.cpp
#include <iostream>
#include <conio.h>
#include <string.h>
#include <windows.h>
#include <ctime>
#include <fstream>
#include "PEND.h"
#define OR ||
#define AND &&
using namespace std;
PEND::PEND()
{
raw=0;
srand(time(0));
for(int i=0;i<=90;i++)
{
if(i%2==0)
{
Password[i]=rand()%26+65;
raw++;
if(raw==2)
{
Password[i]=rand()%26+97;
raw=0;
}
}
else
Password[i]=rand()%10+48;
}
}
void PEND::menu()
{
cout << "Password Encryption And Decryption"
<< "\n[E] Encryption"
<< "\n[D] Decryption"
<< "\n[A] About"
<< "\n[Q] Quit"
<< "\n\nPlease Note That Original and Encrypted Both Passwords Are Case Sensitive."
<< "\n\nPlease Choose Any Option : ";
}
void PEND::Encryption()
{
cout << "\n\nPlease Choose A Secret ID For Your Password : ";
cin >> Rid;
cout << "\nEnter Password For Encryption. B/W (6-30) Characters : ";
cin >> UString;
key=strlen(UString);
if(key < 6 OR key > 31)
{ cout << "\nPassword Must be B/w 6 to 30 Characters\n\n"; }
else
{
for(int i=0;i<key;i++)
{
Password[i*3]=UString[i]+(key/5);
}
Password[key*3] = '\0';
cout << "\nEncrypted Password is : " << Password;
cout << "\nPlease Don't Give Your Secret ID to Anyone. You Can Only Access Your Password With The Secret Key Provide By You :)\n\n";
WFile();
}
}
void PEND::Decryption()
{
cout << "\nEnter Encrypted Password : ";
cin >> Password;
cout << "\nEnter Secret ID : ";
cin >> Rid;
bool frv=CheckID();
if(frv==0)
{
cout << "\nRecord Doesn't Exist Please Check Your Secret ID or Encrypted Password. Please Make Sure That Password is Case Sensitive\n\n";
}
else
{
key=strlen(Password);
raw=0;
for(int i=0;i<key;i+=3)
{
UString[raw]=Password[i];
raw++;
}
UString[raw]='\0';
key=strlen(UString);
if(key>5)
{
for(int i=0;i<key;i++)
{
UString[i]-=(key/5);
}
}
else
{
for(int i=0;i<key;i++)
UString[i]-=key;
}
UString[key] = '\0';
cout << "\nDecrypted Password is : " << UString << endl << endl;
}
}
void PEND::about()
{
cout << "\nThis is About Me Function :)\n\n";
}
void PEND::WFile()
{
ofstream PFile("Password.txt", ios::app);
PFile << Rid << ' ' << Password << endl;
PFile.close();
}
bool PEND::CheckID()
{
int Sid;
string searchp;
ifstream PFile("Password.txt");
while(PFile >> Sid >> searchp)
{
if(Sid==Rid AND searchp==Password)
return 1;
}
return 0;
}
main.cpp
#include <iostream>
#include <conio.h>
#include <windows.h>
#include "PEND.h"
#define OR ||
using namespace std;
int main()
{
PEND a1;
char op;
do
{
a1.menu();
op=getche();
switch(op)
{
case 'E':
case 'e':
a1.Encryption();
break;
case 'D':
case 'd':
a1.Decryption();
break;
case 'A':
case 'a':
a1.about();
break;
case 'Q':
case 'q':
exit(0);
default:
cout << "\nPlease Choose From Given Options :) \n\n";
}
getch();
system("cls");
}
while(op!='q' OR op!='Q');
return 0;
}