Important alert: (current site time 7/15/2013 5:50:46 PM EDT)
 

VB icon

__GusCrypt 1.0v_Encryption Program

Email
Submitted on: 5/3/2005 11:23:27 PM
By: Gustavo Moraes 
Level: Beginner
User Rating: By 4 Users
Compatibility: C, C++ (general), Microsoft Visual C++, Borland C++, UNIX C++
Views: 13198
(About the author)
 
     Easy way to encrypt and decrypt any type of files, with password protection.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: __GusCrypt 1.0v_Encryption Program
// Description:Easy way to encrypt and decrypt any type of files, with password protection.
// By: Gustavo Moraes
//
// Inputs:Tell what file to be encrypt/decrypt,Whats the new file, and what password you want to use.
//
// Returns:A totally encrypted file impossible to decrypt without the password.
//
// Assumes:Easy code, only need to know the basics of c/c++
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=9340&lngWId=3//for details.//**************************************

#include <fstream.h>
#include <iostream.h>
#include <stdlib.h>
/******** Streams ********/
ifstream FileRead;
ofstream FileWrite;
/******* Variables *******/
char szInput;
char szYN = 'Y';
char szTempFileName;
char szTempChar;
char szPassword[7];
int x = 0;
/******* Functions *******/
void GetInfo();
void Encrypt();
void Entrance();
/******* Functions *******/
int main(int argc, char* argv[])
{
 while (szYN == 'Y' || szYN == 'y')
 {
 if(argc == 3)
 {
 FileRead.open(argv[1], ios::in | ios::binary);
 FileWrite.open(argv[2]);
 }
 else
 {
 Entrance();
 GetInfo(); // Get user input
 cout << endl << "Please wait......." << endl;
 Encrypt(); // Encrypt file
 }
 // Close opened files
 FileRead.close();
 FileWrite.close();
 cout << endl << "Done...." << endl;
 cout << "is there anything else I can help you with? (Y or N) : ";
 cin >> szYN;
 system("CLS");
 }
 return 0;
}
void Entrance()
{
 cout << "*******************************************************************************" << endl;
 cout << "*******************************************************************************" << endl;
 cout << "************* Gustavo Moraes *************" << endl;
 cout << "************* GusCrypt Program 1.0 *************" << endl;
 cout << "************* *************" << endl;
 cout << "************* Encryption Program that uses the password to *************" << endl;
 cout << "************* encrypt the file. *************" << endl;
 cout << "*******************************************************************************" << endl;
 cout << "*******************************************************************************" << endl;
 cout << endl;
}
void GetInfo()
{
 char szTempFileName[4096];
 // File to be Encrypted of Decrypted
 cout << "File to be encrypted/decrypted? : ";
 cin >> szTempFileName;
 FileRead.open(szTempFileName, ios::in | ios::binary);
 // Output of the file
 cout << "Output file? : ";
 cin >> szTempFileName;
 FileWrite.open(szTempFileName, ios::out | ios::binary);
 // Password
 cout << "What's the Password? (max.8) : ";
 cin >> szPassword;
}
void Encrypt()
{
 // do while not end of file
 while(!FileRead.eof())
 {
 szInput = FileRead.get(); // Get character
 szTempChar = szInput ^ szPassword[x]; // Xor Character
 if (FileRead.eof()) // if end of file leave this loop
 {	return;	}
 FileWrite << szTempChar; // place encrypted/decrypted char in output
 x++; // next char in password
 if (szPassword[x] == '\0') // is char is blank go back to first char
 {x = 0;}
 // clear variables
 szTempChar = 0;
 szInput = 0;
 }
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

5/16/2006 12:19:09 AM

I'm not sure if its just my compiler (Bloodshed Dev c++)but when I ran the program, I didn't get a chance to enter the output file or password. It just said please wait and just stood there. If you have any advice to get it working, that'd be cool. Thx
(If this comment was disrespectful, please report it.)

 
12/6/2006 8:38:38 AMreyazcpp

hi...........
(If this comment was disrespectful, please report it.)

 
5/11/2007 1:42:40 AMchunkz

hey... can u make a progam that can enrypt a textfile saved on a folder and decrypt it also.. tnx
(If this comment was disrespectful, please report it.)

 
1/22/2010 6:40:24 PMcoder1000

[ visual c++ ] it wont debug or run because of missing header files
(If this comment was disrespectful, please report it.)

 
3/21/2011 11:00:52 AMalchix

Hello...!! Is it meant to be so large the encoded file? I got 4Gb for a 10Kb "cpp" file (borland c++ 5) or is there any other code that suits better??
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.