Convert "string" functions into "char ...[]" functions

Hey

I used a XOR-encryption method to en- and decrypt strings.
Link to this article: http://www.cplusplus.com/forum/articles/38516/
It works perfectly!

But I'm always using the type of "char name[500]" string.
Changing the string itself isn't the problem, but two lines
are difficult to convert:

1
2
encrypted += original[temp] ^ (int(key) + temp) % 255;
unencrypted += encrypted[temp] ^ (int(key) + temp) % 255;


I tried it by using strcat() and some other for-loops.
I also don't really understand what this part of the code does

(int(key) + temp) % 255

Some explanation would be helpful :D

ANproCUBE
Oh never mind, I found out how :)
Last edited on
Hey

For all those who are interested in the code:

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
//Includes
#include <stdio.h>
#include <conio.h>
#include <windows.h>

//Functions
void main()
{
	int temp;
	char original[1000];
	char encrypted[1000];
	char unencrypted[1000];
	char passwd[1000];

	printf("\n Encrypt: ");
	gets(original);
	printf(" Key: ");
	gets(passwd);

	printf("\n\n Unencrypted: %s", original);
	for (int i = 0; i < strlen(passwd); i++)
	{
		for (temp = 0; temp < strlen(original); temp++)
		{
			encrypted[temp] = original[temp] ^ (int(passwd[i]) + temp) % 255;
		}
	}

	encrypted[temp] = '\0';
	printf("\n Encrypted: %s", encrypted);

	for (int i = 0; i < strlen(passwd); i++)
	{
		for (temp = 0; temp < strlen(original); temp++)
		{
			unencrypted[temp] = encrypted[temp] ^ (int(passwd[i]) + temp) % 255;
		}
	}

	unencrypted[temp] = '\0';
	printf("\n Unencrypted: %s", unencrypted);

	_getch();
}
Topic archived. No new replies allowed.