Hi all,
I've tried to write a function for light encrytion for
encrypting personal information (think of addresses, cc numbers etc) in my database. Now here is the problem, Im not getting them back !!!
(Maybe the encryption is better than I thought lol)
Very weird but I dont know why.
Down below you'll find the procedure I've written.
Str is the string that's going to be encrypted/decrypted.
Encrypt boolean value tells function wether it should
encrypt or decrypt.
What I do is I take a single char get its position in the
ASCII table and add a random number, and then change it back
to a char in the ASCII table. Then I make the first char of
the string the number I used to encrypt it with. Thats how
I encrypt it.
To decrypt it, I get the first char, change the first char
and change it back to a number. Then I do the same as before
only I subtract it.
I hope you guys can help me out, BobbaFet
Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
I've tried to write a function for light encrytion for
encrypting personal information (think of addresses, cc numbers etc) in my database. Now here is the problem, Im not getting them back !!!
(Maybe the encryption is better than I thought lol)
Very weird but I dont know why.
Down below you'll find the procedure I've written.
Str is the string that's going to be encrypted/decrypted.
Encrypt boolean value tells function wether it should
encrypt or decrypt.
What I do is I take a single char get its position in the
ASCII table and add a random number, and then change it back
to a char in the ASCII table. Then I make the first char of
the string the number I used to encrypt it with. Thats how
I encrypt it.
To decrypt it, I get the first char, change the first char
and change it back to a number. Then I do the same as before
only I subtract it.
Code:
function ChangeChars(Str: String; Encrypt: Boolean): String;
var UseNum, i: Integer;
begin
Usenum := 0; i := 0; Result := '';
if Encrypt then
begin
Randomize;
UseNum := Round(Random(100)) + 22;
for i := 0 to Length(Str) do
begin
Result := Result + Chr(Ord(Str[i]) + UseNum);
end;
Result := Chr(UseNum) + Result;
end
else
begin
UseNum := Ord(Str[1]);
Delete(Str,0,1);
for i := 0 to Length(Str) do
begin
Result := Result + Chr(Ord(Str[i]) - UseNum);
end;
end;
Result := Result;
end;
I hope you guys can help me out, BobbaFet
Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com