i am making a program to implement xor encryption,while playing around with my program i entered various key combinations the program was working perfectly until i entered value of key : 904932 which caused ommition of ‘d’ character e.g if i enter ‘hi my name is dexter and i hate my stupid sister dede’ in edit1,encrypting and decrypting back will
make my edit1 text :’hi my name is exter an i hate my stupi sister ee’
what is going on?
procedure TForm2.Button1Click(Sender: TObject);
var
c:char;
i,key: integer;
begin
s := edit1.Text;
edit1.Text := #0;
key := strtoint(edit2.text);
key := key + 128;//i am adding 128 so that i dont get NULL char
for I := 1 to length(s) do {or 0 to lenght(s)? i dont know}
begin
c := s[i];
c := char(ord(c) xor key);
edit1.Text := edit1.Text + c;
end;
end;
Adding 128 won’t solve your problem. It just moves it.
Your “xor key” just xor the last byte of your key, that is $E4 in your case of 904932.
$E4+128 will be rounded (i.e. -256) to byte value 100, which is the ASCII value of “d”.
That’s why your “d” disappeared.
So I guess should NOT use such a xor algorithm if you want to display the encrypted text.
I’d suggest that you make some simple permutation algorithm.