Encryption

Pages: 12
closed account (4i67ko23)
Still errors that those lines:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <windows.h>
#include <fstream>
#include <string>

#define ENCRYPT "123456789 - abcdefg"

using std :: cout;
using std :: endl;
void encrypt( char [ ] ); // prototypes of functions used in the code
void decrypt( char * ePtr );
using namespace std;
int main( )
{
    string line;
    ifstream read_input ("text.txt");
    if (read_input.is_open())
    {
        while ( read_input.good() )
        {
            getline (read_input,line);  //input is already read into variable "line"
            cout << "Original string is: " << line << endl;
            encrypt( line.c_str() );
            // call to the function encrypt( )
            cout << "Encrypted string is: " << line << endl;
            ofstream encode;
            encode.open ("encoded.txt");
            encode << line;
            encode.close();
            decrypt( line.c_str() );
            // call to the function decrypt( )
            cout << "Decrypted string is: " << line << endl;
            ofstream decode;
            decode.open ("decoded.txt");
            decode << line;
            decode.close();
        }
        read_input.close();
    }
    else cout << "Unable to open file"; 
    Sleep(10000);
    return 0;
}// main

//encrypt data
void encrypt (char e[] ) 
{
    for( int i=0; e[i] != '\0'; ++i ) ++e[i];
} // encrypt

//decrypt data
void decrypt( char * ePtr ) 
{
    for( ; * ePtr != '\0'; ++ ePtr ) --(* ePtr);
}



23 C:\Users\Mathijs\Documents\C++\encrypter.cpp invalid conversion from `const char*' to `char*'

23 C:\Users\Mathijs\Documents\C++\encrypter.cpp initializing argument 1 of `void encrypt(char*)'

30 C:\Users\Mathijs\Documents\C++\encrypter.cpp invalid conversion from `const char*' to `char*'

30 C:\Users\Mathijs\Documents\C++\encrypter.cpp initializing argument 1 of `void decrypt(char*)'
Try this:

1
2
3
char myChar[100];
strncpy(myChar, line.c_str(), line.size());
encrypt(myChar);
closed account (4i67ko23)
Allride!
It works, no errors. It only doesn't encryp.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <windows.h>
#include <fstream>
#include <string>

#define ENCRYPT "123456789 - abcdefg"

using std :: cout;
using std :: endl;
void encrypt( char [ ] ); // prototypes of functions used in the code
void decrypt( char * ePtr );
using namespace std;
int main( )
{
    string line;
    ifstream read_input ("text.txt");
    if (read_input.is_open())
    {
        while ( read_input.good() )
        {
            getline (read_input,line);  //input is already read into variable "line"
            cout << "Original string is: " << line << endl;
            //encrypt( line.c_str() );
            char myChar[100];
            strncpy(myChar, line.c_str(), line.size());
            encrypt(myChar);
            // call to the function encrypt( )
            cout << "Encrypted string is: " << line << endl;
            ofstream encode;
            encode.open ("encoded.txt");
            encode << line;
            encode.close();
            //decrypt( line.c_str() );
            char myChar2[100];
            strncpy(myChar2, line.c_str(), line.size());
            decrypt(myChar2);
            // call to the function decrypt( )
            cout << "Decrypted string is: " << line << endl;
            ofstream decode;
            decode.open ("decoded.txt");
            decode << line;
            decode.close();
        }
        read_input.close();
    }
    else cout << "Unable to open file"; 
    Sleep(10000);
    return 0;
}// main

//encrypt data
void encrypt (char e[] ) 
{
    for( int i=0; e[i] != '\0'; ++i ) ++e[i];
} // encrypt

//decrypt data
void decrypt( char * ePtr ) 
{
    for( ; * ePtr != '\0'; ++ ePtr ) --(* ePtr);
}



text.txt Hello There!

encoded.txt Hello There!

decoded.txt Hello There!
Replace :
cout << "Encrypted string is: " << line << endl;

with :
cout << "Encrypted string is: " << myChar << endl;

and replace:
encode << line;

with:
encode << myChar;

closed account (4i67ko23)
Great!!
The code finaly works!
Thanks all!
Here is the final source, I'm gone add some extras
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <windows.h>
#include <fstream>
#include <string>

#define ENCRYPT "123456789 - abcdefg"

using std :: cout;
using std :: endl;
void encrypt( char [ ] ); // prototypes of functions used in the code
void decrypt( char * ePtr );
using namespace std;
int main( )
{
    string line;
    ifstream read_input ("text.txt");
    if (read_input.is_open())
    {
        while ( read_input.good() )
        {
            getline (read_input,line);
            cout << "Original string is: " << line << endl;
            //encrypt( line.c_str() );
            char myChar[100];
            strncpy(myChar, line.c_str(), line.size());
            encrypt(myChar);
            // call to the function encrypt( )
            cout << "Encrypted string is: " << myChar << endl;
            ofstream encode;
            encode.open ("encoded.txt");
            encode << myChar;
            encode.close();
            //decrypt( line.c_str() );
            decrypt(myChar);
            // call to the function decrypt( )
            cout << "Decrypted string is: " << myChar << endl;
            ofstream decode;
            decode.open ("decoded.txt");
            decode << myChar;
            decode.close();
        }
        read_input.close();
    }
    else cout << "Unable to open file"; 
    Sleep(10000);
    return 0;
}// main

//encrypt data
void encrypt (char e[] ) 
{
    for( int i=0; e[i] != '\0'; ++i ) ++e[i];
} // encrypt

//decrypt data
void decrypt( char * ePtr ) 
{
    for( ; * ePtr != '\0'; ++ ePtr ) --(* ePtr);
}
Topic archived. No new replies allowed.
Pages: 12