imported_dheeraj_kumar
Journeyman
I wrote an encryption/decryption prog in c++ using the xor operator(im just a n00b)
suppose my input is
my name is dheeraj kumar.
then my encrypted form is
㵧≥㙁刁Ԁ幅㸵ጕȕൽĜᰄ鉏
when i decrypt it the output is
my name is dheeraj kumar.ÿš
i dont know how i got the extra 2 characters in the end, i even debugged it but to no avail, so someone help me out here.
i did this as a school project, and i need to submit it on friday, so someone please help fast.
here is my code:
basically what i am doing is:
get a password from the user
xor the whole text with the password
find the sum of the letters' ascii number and xor the whole text with that
xor with password
xor with sum
xor with sum
with password
sum again
the password again
repeat the process to decrypt it.
and please omit the commented code.
thanks
Dheeraj Kumar
suppose my input is
my name is dheeraj kumar.
then my encrypted form is
㵧≥㙁刁Ԁ幅㸵ጕȕൽĜᰄ鉏
when i decrypt it the output is
my name is dheeraj kumar.ÿš
i dont know how i got the extra 2 characters in the end, i even debugged it but to no avail, so someone help me out here.
i did this as a school project, and i need to submit it on friday, so someone please help fast.
here is my code:
Code:
#include <fstream.h>
#include <graphics.h>
#include <math.h>
#include <stdio.h>
#include <conio.h>
#include <process.h>
//#include "C:\Turbo\TC\Project\Code\3dSP.cpp"
//#include "C:\Turbo\TC\Project\Mouse.cpp"
class program
{
// V A R I A B L E D E C L A R A T I O N
// S t r e a m s
ifstream FileRead;
ofstream FileWrite;
// V a r i a b l e s
char Input;
char TempFileName;
char TempChar;
char *TempText;
char *Password;
char *FinalText;
char *filread;
char *filwrite;
int x;
// F U N C T I O N S
public:
void EncFile()
{
clrscr();
Input=' ';
TempChar=' ';
TempText=" ";
Password=" ";
FinalText=" ";
filread=" ";
filwrite=" ";
int sum=0;
char *output= " ";
char *TempFileName=" ";
// File to be Encrypted of Decrypted
cout << "File to be encrypted/decrypted? : ";
gets(TempFileName);
FileRead.open(TempFileName, ios::in | ios::binary);
// Output of the file
cout << "Output file? : ";
gets(output);
FileWrite.open(output, ios::out | ios::binary);
// Password
cout << "What's the Password? (max.8) : ";
gets(Password);
for(int i=0;Password[i]!='\0';i++)
sum+=Password[i];
sum%=100;
cout<<endl<<"Processing, please wait......." << endl;
FileRead.seekg(0);
FileWrite.seekp(0);
for(i=0; !FileRead.eof(); i++)
{
//float percent = (i/filsize)*100;
//gotoxy(0,5);
//cout<<"File Encryption Process : "<<percent<<" %"<<endl;
Input = FileRead.get(); // Get character
TempChar = Input ^ Password[x]; // Xor Character
FileWrite << TempChar; // place encrypted/decrypted char in output
x++; // next char in password
if (Password[x] == '\0') // if char is blank go back to first char
x=0;
TempChar = 0;
Input = 0;
}
FileRead.seekg(0);
FileWrite.seekp(0);
for(i=0; !FileRead.eof(); i++)
{
//float percent = (i/filsize)*100;
//gotoxy(0,5);
//cout<<"File Encryption Process : "<<percent<<" %"<<endl;
Input = FileRead.get(); // Get character
TempChar = Input ^ sum; // Xor Character
FileWrite << TempChar; // place encrypted/decrypted char in output
TempChar = 0;
Input = 0;
}
FileRead.seekg(0);
FileWrite.seekp(0);
for(i=0; !FileRead.eof(); i++)
{
//float percent = (i/filsize)*100;
//gotoxy(0,5);
//cout<<"File Encryption Process : "<<percent<<" %"<<endl;
Input = FileRead.get(); // Get character
TempChar = Input ^ Password[x]; // Xor Character
FileWrite << TempChar; // place encrypted/decrypted char in output
x++; // next char in password
if (Password[x] == '\0') // if char is blank go back to first char
x=0;
TempChar = 0;
Input = 0;
}
FileRead.seekg(0);
FileWrite.seekp(0);
for(i=0; !FileRead.eof(); i++)
{
//float percent = (i/filsize)*100;
//gotoxy(0,5);
//cout<<"File Encryption Process : "<<percent<<" %"<<endl;
Input = FileRead.get(); // Get character
TempChar = Input ^ sum; // Xor Character
FileWrite << TempChar; // place encrypted/decrypted char in output
TempChar = 0;
Input = 0;
}
FileRead.seekg(0);
FileWrite.seekp(0);
for(i=0; !FileRead.eof(); i++)
{
//float percent = (i/filsize)*100;
//gotoxy(0,5);
//cout<<"File Encryption Process : "<<percent<<" %"<<endl;
Input = FileRead.get(); // Get character
TempChar = Input ^ sum; // Xor Character
FileWrite << TempChar; // place encrypted/decrypted char in output
TempChar = 0;
Input = 0;
}
FileRead.seekg(0);
FileWrite.seekp(0);
for(i=0; !FileRead.eof(); i++)
{
//float percent = (i/filsize)*100;
//gotoxy(0,5);
//cout<<"File Encryption Process : "<<percent<<" %"<<endl;
Input = FileRead.get(); // Get character
TempChar = Input ^ Password[x]; // Xor Character
FileWrite << TempChar; // place encrypted/decrypted char in output
x++; // next char in password
if (Password[x] == '\0') // if char is blank go back to first char
x=0;
TempChar = 0;
Input = 0;
}
FileRead.seekg(0);
FileWrite.seekp(0);
for(i=0; !FileRead.eof(); i++)
{
//float percent = (i/filsize)*100;
//gotoxy(0,5);
//cout<<"File Encryption Process : "<<percent<<" %"<<endl;
Input = FileRead.get(); // Get character
TempChar = Input ^ sum; // Xor Character
FileWrite << TempChar; // place encrypted/decrypted char in output
TempChar = 0;
Input = 0;
}
FileRead.seekg(0);
FileWrite.seekp(0);
for(i=0; !FileRead.eof(); i++)
{
//float percent = (i/filsize)*100;
//gotoxy(0,5);
//cout<<"File Encryption Process : "<<percent<<" %"<<endl;
Input = FileRead.get(); // Get character
TempChar = Input ^ Password[x]; // Xor Character
FileWrite << TempChar; // place encrypted/decrypted char in output
x++; // next char in password
if (Password[x] == '\0') // if char is blank go back to first char
x=0;
TempChar = 0;
Input = 0;
}
FileRead.close();
FileWrite.close();
cout<<endl <<"Encryption Process Completed"<<endl;
cout<<"Press any key to continue...";
getch();
}
void menu()
{
clrscr();
for(int i=0;i<479;i++)
{ if(i%8==0)
outtextxy(0,i,"º º");
}
//outtextxy(0,0,"É������������������������������������������������������������������������������»");
//outtextxy(0,8,"º º");
getch();
}
};
void main()
{
program prog;
//int gdriver = DETECT, gmode, errorcode;
//initgraph(&gdriver, &gmode, "");
prog.EncFile();
//prog.menu();
}
basically what i am doing is:
get a password from the user
xor the whole text with the password
find the sum of the letters' ascii number and xor the whole text with that
xor with password
xor with sum
xor with sum
with password
sum again
the password again
repeat the process to decrypt it.
and please omit the commented code.
thanks
Dheeraj Kumar