Warning: Non-static method vBSEO_Storage::path() should not be called statically in ..../vbseo/includes/functions_vbseo_pre.php on line 387

Warning: Non-static method vBSEO_Storage::path() should not be called statically in ..../vbseo/includes/functions_vbseo_pre.php on line 387

Warning: Non-static method vBSEO_Storage::path() should not be called statically in ..../vbseo/includes/functions_vbseo_seo.php on line 337

Warning: Non-static method vBSEO_Storage::path() should not be called statically in ..../vbseo/includes/functions_vbseo_seo.php on line 339

Warning: Non-static method vBSEO_Storage::path() should not be called statically in ..../vbseo/includes/functions_vbseo_seo.php on line 341

Warning: Non-static method vBSEO_Storage::path() should not be called statically in ..../vbseo/includes/functions_vbseo_seo.php on line 343
[Help] XOR encryptor

Results 1 to 3 of 3
  1. #1
    Coders NightGhost's Avatar
    Join Date
    Apr 2006
    Posts
    658

    [Help] XOR encryptor

    Hello, I'm working on a xor encryptor, but I can't get around an access violation error..

    I know how XOR works, and I've written a pascal xor encryption program very simular to the c++ one below...

    I'm pretty sure that its a very simple mistake.
    Please take a look at the code:

    Code:
    #include <iostream>
    #include <windows.h>
    
    using namespace std;
    
    char * chEncrypt( char * sString, char cKey )
    {
    	for( int i = 0; i < strlen(sString); i++ )
    	{	sString[i] ^= cKey;	}
    
    	return sString;
    }
    
    int main( )
    {
    	cout << chEncrypt( "Hello world", 'x' ) << endl;
    
    	system("pause");
    	return 0;
    }
    Greets,
    ~NightGhost

  2. #2
    Coders Shard's Avatar
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    213

    Re: [Help] XOR encryptor

    Quote Originally Posted by NightGhost View Post
    Hello, I'm working on a xor encryptor, but I can't get around an access violation error..

    I know how XOR works, and I've written a pascal xor encryption program very simular to the c++ one below...

    I'm pretty sure that its a very simple mistake.
    Please take a look at the code:

    Code:
    ...
    Greets,
    ~NightGhost
    It's because you're passing a constant to your function which is (apparently) read-only when it needs something that it can write to.
    Code:
     #include <iostream>
    #include <windows.h>
    
    using namespace std;
    
    char * chEncrypt( char * sString, char cKey )
    {
        for( int i = 0; i < strlen(sString); i++ )
        {    sString[i] ^= cKey;    }
    
        return sString;
    }
    
    int main( )
    {
        char sString[32];
        sprintf( sString, "Hello world" );
    
        cout << chEncrypt( sString, 'x' ) << endl;
    
        system("pause");
        return 0;
    }

  3. #3
    Coders NightGhost's Avatar
    Join Date
    Apr 2006
    Posts
    658

    Re: [Help] XOR encryptor

    Quote Originally Posted by Shard View Post
    It's because you're passing a constant to your function which is (apparently) read-only when it needs something that it can write to.
    Code:
    ...
    Works great ;D!

    Thanks for the help.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •