• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

need some help, fellaz

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Bmxpunk86pl

Member
Joined
Sep 7, 2001
Location
CT/Poland
Hey wuts up

Ok im writing a little encryption progarm in C++, here is my souce code:

#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
char string [10] = "adam";

char key [10] = "abcd";

string = string ^ key;



system ("pause");

return 0;
}

I try to compile this program but i get a error saying
"invalid operands 'char[10' to binary 'operator^'


Can anyone help me?


Thanks,
Adam
 
Probably can't exponentiate with a char. Try assigning the values of a, b, c, d to an int array or something.

More complex encryption uses matrix multiplication.
 
It says that because you are trying to assign an address to an array, and an array's name is a constant pointer. It cannot be changed.

string = string ^ key;

It should be

*string = *string ^ *key;

In this way, you are derefering the first value pointed to by the array variable string which would in this case be the character "a".
 
Never tried it myself, but I'm guessing you can't do a binary XOR on an array, which is what those are. Try doing a for loop to go through and XOR each individual character in the string.

for(int i = 0; i < 10; i++)
{
string = string ^ key;
}

and if you can't XOR chars, just cast them as ints before doing the conversion.
 
You can definately XOR characters :)

Here's a sample program I am showing, though it only encrypts the string using one single character

Code:
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
	char string[] = "Naif";
        char key = 'X'; /* The value of key is used for xoring the string */
	int count;	/* Counter */

	printf("string before encryption: %s\n\n",string);

	for(count = 0;count < strlen(string);count++)
		string[count] = string[count] ^ key;

/*
        You could also use a faster algorithm/method which could be

	count = 0;
	while(*(string+count) != NULL) {
		*(string+count) = *(string+count) ^ key;
		count++;
	}

	This isnt the most optimising method, there are too many methods
	to show	here
*/

	printf("string after encryption: %s\n",string);
}
 
ok thanks alot...wuts "matrix multiplication"?

Also what can i classify my encryption as? 5 bit?
 
Last edited:
Back