Thread: Help with my XOR routine..

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964

    Help with my XOR routine..

    I know that this topic has been covered a million times already, but i went through all the XOR topics on the site without figuring out what i am doing wrong in my own program?

    I've attached the main program file to my post, the XOR function is defined in it's own file:

    Code:
    /* Source file for the XOR routine */
    
    /* Include the function prototype */
    #include "xor.h"
    
    /* XOR-funtion declaration */
    std::string XOR(std::string line, std::string key)
    {
    		unsigned int i = 0, j = 0;					
    		std::size_t l_length, k_length;				
    		std::string e_line;		
    					
    	l_length = line.length();
    	k_length = key.length();
    	
    	for(;i < l_length; i++, j++)					
    	{
    		e_line[i] = line[i] ^ key[j];				
    		
    		if(j == k_length)							
    		{
    			j = 0;
    		}
    	}
    
    	/* Return the encrypted line */
    	return e_line;
    }
    Removed most of my comments since the forums are screwing up indentation.


    I compile my project from the command line like this:
    "g++ -omain.exe -Wall -pedantic xor.cpp main.cpp"

    But when i run the program, nothing happens after i enter the key, i don't get any output to the outputfile, and the program just closes. Where in my code is the problem?

    EDIT: Accidentally wrote "crashes" rather than "closes", my program doesn't crash or segfault or anything, it just closes without outputting to the outputfile.
    Last edited by Neo1; 10-04-2007 at 06:11 AM.

Popular pages Recent additions subscribe to a feed