I agree with tux4life's comments. Seems like an awful lot of double/triple/quadruple posts to blame on packet loss/slow loading. However, Daniweb can be maddeningly slow to load, so I've had to repost numerous times, though I try to wait to make sure my last post truly hasn't gone through. That doesn't explain the lack of code tags, though. You simply didn't read the announcements. You're also coming across as really pushy and demanding. It seems like you googled for an encryption program, found a random one on Dream In Code that you don't understand, and then want to change it, which is difficult if you are the complete novice that you say you are. You need to start with some tutorials and work up, like everyone does.

However, I'm willing to give you the benefit of the doubt that it wasn't intentional, so I'll tell you what you appear to be missing.

Go to post 22, copy lines 5 through 23 from that post, and post them where line 7 is in your last post. See if that solves it. If it doesn't, I'm sorry, but I have no more time to spend on this thread. Read the links tux4life posted and try to take them to heart. You should mark this thread "solved" now. Feel free to start new threads on a new topic, but again, read the links and tux4life's comments and try to learn from them.

Good luck.

tux4life commented: Agree +22

Dear Sir,
Thanks for guidence, i am Thankful to tux4life and VernonDozier, but grace of God and the help provided by you people i have reached to solution, by now i am able to encrypt and decrypt files with the program.

About 99% of the problem is solved, I am facing a little problem that if i encypt large files using program it encrypts and after decryption the about 6 to 7 lines are decrypted only.

i am sending the code so that somebody can help me solve the problem cent per cent.
let say we put the code of the following program in a text file
e.g
plain.txt

and we decrypt it
into cypher.txt

after decryption to another file let say plainout.txt
it only gives
#include <iostream>
#include <stdli
the whole code is not decrypted

#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <stdio.h>
using namespace std;
bool password();
char encrypt (char c)
{
    int a = c;
    if (a < 0)
        a = a + 256;
    int b = a * 37;
    char d = b % 200;
    return d;
}

char decrypt (char c)
{
    int a = c;
    if (a < 0)
        a = a + 256;
    int b = a * 173;
    char d = b % 200;
    return d;
}
void doCrypt(char *cool)
{
     int cryp;//the main int this function uses
    char x;//to get the chars from the file
    ifstream in;//the input stream
    ofstream out;//the output stream
    in.open(cool);//opening the input file
    if(in.fail()){//check if it's not there
         cout<<"Couldn't open the IN file\n";//if it's not, print
        return;
    }
    cout<<"enter the OUT file name: ";//enter the output filename
    cin>>cool;//get it
    //cin.getline(cool, 20);
    out.open(cool);//open the output file
    //
    if(!in.is_open())
   return;
while(in.get(x)) {//while x is not beyong End Of File
    //cryp=x-0xFACA;//the crypting
    cryp = encrypt (x);
    out<<(char)cryp;//print the crypted char
}
    //
   /* in.get(x);//get the first char of input
    if(in.eof())//if read beyong end of file
         return;//quit
    while(x != EOF){//while x is not beyong End Of File
         //cryp=(x*37)%200;//the crypting
cryp = encrypt (x);
        out<<(char)cryp;//print the crypted char
        in.get(x);//get another char
        if(in.eof())//if read beyong end of file
             break;
    } */
    in.close();
    out.close();
    return;
}
void deCrypt(char *daf)
{
     int decr;//the main int
    char x;//the input char
    ifstream in;//input stream
    ofstream out;//output stream
    in.open(daf);//open the inout stream
    if(in.fail()){//see if it's not there
         cout<<"Error couldn't openn the IN file\n";//print
        return;
    }
    cout<<"Enter the OUT file name: ";//ask for the out filename
    cin>>daf;
    out.open(daf);//open the outfile
    //
    if(!in.is_open())
   return;
while(in.get(x)) {//while x is not beyong End Of File
    //cryp=x-0xFACA;//the crypting
 decr = decrypt (x);
    out<<(char)decr;//print the crypted char
}
    //
/*    in.get(x);//get the input char
    if(in.eof())//if read beyong end of file
         return;
    while(x!=EOF){//while x is not beyong end of file
 // decr=(x*173)%200;//the dectypring
decr = decrypt (x);
        out<<(char)decr;
        in.get(x);//get the next char
        if(in.eof())//if read beyong the eon of file
             break;
             system("pause");
    }   */
    return;
}
int main(void)

{
/*    
if (password()) cout << "Access Granted: \n";
    else
    {
    cout << "You are not Authorized to use this program!\n";
    system("pause");
    return 0;
    }
*/
    char *cool=new char[20];//the name pointer
    char nav;              //"navigation char"

    cout << "*---------------------------------------------*\n";
    cout << "| This is an encryption program.  I'm not     |\n";
    cout << "| taking credit for this.  This was a         |\n";
    cout << "| recent submission on planet-source-code     |\n";
    cout << "| I just added password protection to it.     |\n";
    cout << "*---------------------------------------------*\n\n";
    system("pause");
    cout << "\n\n";
    cout << "Use \"m\" for the Menu\n";//print instructions
     while(true){
         cin >> nav;
         switch(nav){
             case 'm':
                 cout << "COMMAND\tFUNCTION\n";
                cout << "e      \tencrypt\n"
                          "d      \tdecrypt\n"
                        "m      \t menu \n"
                        "q      \t quit \n";
                break;
             case 'e':
                 cout << "Enter the file name: \nExample: \"file\".txt\n";
                cin >> cool;
                //cin.getline(cool, 20);
                doCrypt(cool);
                break;
            case 'd':
                 cout << "Enter the file name: ";
                cin >> cool;
                //cin.getline(cool, 20);
                deCrypt(cool);
                break;
            case 'q':
                 exit(0);
                 break;
            default:
                 cout << "I do not understand you!\n";
                break;
        }
    }
}
/*
bool password()
{
     char string1[50];
     cout << "Enter in the encryption password: \n";
     //gets(string1);
cin.getline(string1, 50);
     if (strcmp(string1, "outlaw")) return 0;
     return 1;
}
*/

Any help will be appreciated

Could you provide us with the file you tried to encrypt/decrypt using your program?

Dear Sir,
Just make a file and paste the whole program in it.
I did the same and encrypted the file/test file containing the code.
the whole test in file was encrypted but it only derypt if two lines and second line is also incomplete.

Thanks!

the detail i have given in post 33

for your ease i have now added text files

plaint.txt input plain text file
cypher.txt output encrypted/cyphered text
plainy.txt output decyphered/decrypted text which is not the same as first input file plaint.txt

hope this might help u understand the problem.

This won't fix your problem, but it will fix a memory leak:
if you write this in your code: char *cool=new char[20];//the name pointer then at some point in future your program doesn't need the memory anymore (for example just before your program terminates, is the memory still needed then? I guess not).
So you'll want to add this line at the end of your main() function: delete[] cool; , this line will free up the previously allocated memory :)

(And yes, I know: some operating systems free up/deallocate all the memory which was associated with the program, at the time when the program terminates, but it doesn't make the step of cleaning up the manually allocated resources unnessesary: not all OSes do offer you this feature, and not manually deallocating your allocated resources can result in a memory leak either when your program is running or even at the moment when your program isn't running anymore (in case your OS doesn't provide some kind of garbage collection))

So, moral of the story: when you manually allocate memory using new then always also manually deallocate it using delete (this will also ensure portability).

The main Problem in your code is that it replaces the letter "b" with the letter in UNICODE represented as "001A", which is the key to break the execution of the program.

#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <stdio.h>
using namespace std;
bool password();
char encrypt (char c)
{
    int a = c;
    if (a < 0)
        a = a + 256;
    int b = a * 37;
    char d = b % 200;
    return d;
}

char decrypt (char c)
{
    int a = c;
    if (a < 0)
        a = a + 256;
    int b = a * 173;
    char d = b % 200;
    return d;
}
void doCrypt(char *cool)
{
     int cryp;//the main int this function uses
    char x;//to get the chars from the file
    ifstream in;//the input stream
    ofstream out;//the output stream
    in.open(cool);//opening the input file
    if(in.fail()){//check if it's not there
         cout<<"Couldn't open the IN file\n";//if it's not, print
        return;
    }
    cout<<"enter the OUT file name: ";//enter the output filename
    cin>>cool;//get it
    //cin.getline(cool, 20);
    out.open(cool);//open the output file
    //
    if(!in.is_open())
   return;
   while(in.get(x)) {//while x is not beyong End Of File
    //cryp=x-0xFACA;//the crypting
    cryp = encrypt (x);
    out<<(char)cryp;//print the crypted char
}
    //
   /* in.get(x);//get the first char of input
    if(in.eof())//if read beyong end of file
         return;//quit
    while(x != EOF){//while x is not beyong End Of File
         //cryp=(x*37)%200;//the crypting
         cryp = encrypt (x);
        out<<(char)cryp;//print the crypted char
        in.get(x);//get another char
        if(in.eof())//if read beyong end of file
             break;
    } */
    in.close();
    out.close();
    return;
}
void deCrypt(char *daf)
{
     int decr;//the main int
    char x;//the input char
    ifstream in;//input stream
    ofstream out;//output stream
    in.open(daf);//open the inout stream
    if(in.fail()){//see if it's not there
         cout<<"Error couldn't openn the IN file\n";//print
        return;
    }
    cout<<"Enter the OUT file name: ";//ask for the out filename
    cin>>daf;
    out.open(daf);//open the outfile
    //
    if(!in.is_open())
   return;
   while(in.get(x)) {//while x is not beyong End Of File
    //cryp=x-0xFACA;//the crypting
    decr = decrypt (x);
    out<<(char)decr;//print the crypted char
}
    //
/*    in.get(x);//get the input char
    if(in.eof())//if read beyong end of file
         return;
    while(x!=EOF){//while x is not beyong end of file
 // decr=(x*173)%200;//the dectypring
decr = decrypt (x);
        out<<(char)decr;
        in.get(x);//get the next char
        if(in.eof())//if read beyong the eon of file
             break;
             system("pause");
    }   */
    return;
}
int main(void)

{
/*    
if (password()) cout << "Access Granted: \n";
    else
    {
    cout << "You are not Authorized to use this program!\n";
    system("pause");
    return 0;
    }
*/
    char *cool=new char[20];//the name pointer
    char nav;              //"navigation char"

    cout << "*---------------------------------------------*\n";
    cout << "| This is an encryption program.  I'm not     |\n";
    cout << "| taking credit for this.  This was a         |\n";
    cout << "| recent submission on planet-source-code     |\n";
    cout << "| I just added password protection to it.     |\n";
    cout << "*---------------------------------------------*\n\n";
    system("pause");
    cout << "\n\n";
    cout << "Use \"m\" for the Menu\n";//print instructions
     while(true){
         cin >> nav;
         switch(nav){
             case 'm':
                 cout << "COMMAND\tFUNCTION\n";
                cout << "e      \tencrypt\n"
                          "d      \tdecrypt\n"
                        "m      \t menu \n"
                        "q      \t quit \n";
                break;
             case 'e':
                 cout << "Enter the file name: \nExample: \"file\".txt\n";
                cin >> cool;
                //cin.getline(cool, 20);
                doCrypt(cool);
                break;
            case 'd':
                 cout << "Enter the file name: ";
                cin >> cool;
                //cin.getline(cool, 20);
                deCrypt(cool);
                break;
            case 'q':
                 exit(0);
                 break;
            default:
                 cout << "I do not understand you!\n";
                break;
                
        }
        
    }
  delete[] cool;  
}

/*
bool password()
{
     char string1[50];
     cout << "Enter in the encryption password: \n";
     //gets(string1);
cin.getline(string1, 50);
     if (strcmp(string1, "outlaw")) return 0;
     return 1;
}
*/

i have added delete[] cool; at the end of main function but didn't worked for me.

plz help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.