Subject | Need help with FB XOR UDF, please |
---|---|
Author | Chuck Belanger |
Post date | 2005-06-03T16:52:21Z |
Hello, all:
I'm trying to use an XOR function to obscure data and because of my
inexperience with String vs PChar seem to be having trouble: the UDF
below works just fine to obscure and de-obscure strings in a Delphi
program, but when used as a FireBird UDF it doesn't properly de-obscure
a previously XOR'd string.
Could anyone please tell me what I need to do to get the original string
field back?
Thank you,
Chuck Belanger
function Str2Str(Value:PChar; Key: integer):PChar;
var
ix : integer;
rString : string ;
begin
RANDSEED := Key;
rString := '';
for ix := 1 to Length(Value^) do
begin
rString := rString +
chr(Ord(Value[ix]) XOR (RANDOM(254)+1));
end;
result := PChar(rString);
end;
DECLARE EXTERNAL FUNCTION F_STR2STR
CSTRING(3072),
INTEGER
RETURNS CSTRING(3072)
ENTRY_POINT 'Str2Str' MODULE_NAME 'FreeUDFLib.dll'
## = some number
below is a test of obscuring and de-obscuring:
(in any case if I use fields, I have the same problem.
select first 1 f_str2str(f_str2str('hello',##), ##), ml_id from
masterlibrary
Why can't I get 'hello' back?
I'm trying to use an XOR function to obscure data and because of my
inexperience with String vs PChar seem to be having trouble: the UDF
below works just fine to obscure and de-obscure strings in a Delphi
program, but when used as a FireBird UDF it doesn't properly de-obscure
a previously XOR'd string.
Could anyone please tell me what I need to do to get the original string
field back?
Thank you,
Chuck Belanger
function Str2Str(Value:PChar; Key: integer):PChar;
var
ix : integer;
rString : string ;
begin
RANDSEED := Key;
rString := '';
for ix := 1 to Length(Value^) do
begin
rString := rString +
chr(Ord(Value[ix]) XOR (RANDOM(254)+1));
end;
result := PChar(rString);
end;
DECLARE EXTERNAL FUNCTION F_STR2STR
CSTRING(3072),
INTEGER
RETURNS CSTRING(3072)
ENTRY_POINT 'Str2Str' MODULE_NAME 'FreeUDFLib.dll'
## = some number
below is a test of obscuring and de-obscuring:
(in any case if I use fields, I have the same problem.
select first 1 f_str2str(f_str2str('hello',##), ##), ml_id from
masterlibrary
Why can't I get 'hello' back?