Skip to main content
GameDev.net gamedev.net
🔒 Locked

simple encryption problem

Started by Damocles Jul 13, 2003 at 1:16 PM 4 replies 900+ views
Original Post
Damocles
Damocles
I''m working on a simple encryption system for a shareware key setup.... Look at this code:
char convertName(int *mult, int num)
{
	int m=0;
	while (num>25)
	{
		num-=26;
		m++;
	}
	num+=(int)''A'';
	*mult=m;
	return (char)num;
}
 
It simply takes a character and returns another character in encrypted form. It first reduces it to the range of 0-25 and then adds ''A'' to it so that the resultant character sits between A and Z. I store mult so that I can store that as the multipler for decryption. The problem is, when it receives the character ''ü'' the resulting character returned is ''=''. If you look at your ascii table, you''ll see that ''='' is actually before ''A'' in the table, so how am I getting an equals sign int he output!? What have I missed here? I must be missing something (probably something simple) but I can''t see it for the life of me btw - before anyone asks why I don''t just use divide and remainder operators, it''s because I''m going to expand it to a more complex system, assuming I can get this simple setup to work first
------------------------------------------[New Delta Games] | [Sliders]
ApochPiQ
ApochPiQ
Use this code instead:


char convertName(int *mult, unsigned char num)
{
int m=0;
while (num>25)
{
num-=26;
m++;
}
num+=(unsigned char)''A'';
*mult=m;
return (char)num;
}



Converting from a char to an int can cause some very strange problems.
Damocles
Damocles
D''oh, I knew it would be something simple. I completely forgot that characters are 8 bits not 16.

At least it''s an easy fix, thanks.
------------------------------------------[New Delta Games] | [Sliders]
Damocles
Damocles
That''s only the beginning of the encrypter. That''s not really enough to go on to break it. I''m just as paranoid as everyone else. Are you looking at me?
------------------------------------------[New Delta Games] | [Sliders]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.