function RNDString(Chars: string; Count: Integer): string;
var
i, x: integer;
begin
Result := '';
for i := 0 to Count - 1 do
begin
x := Length(Chars) - Random(Length(Chars));
Result := Result + chars[x];
Chars := Copy(Chars, 1,x - 1) + Copy(Chars, x + 1,Length(Chars));
end;
end;
function Encode(Data, SecString, CharSet: string; MinV: Integer = 0; MaxV: Integer = 5): string;
var
i, x: integer;
s1, s2, ss: string;
begin
if minV > MaxV then
begin
i := minv;
minv := maxv;
maxv := i;
end;
if MinV < 0 then MinV := 0;
if MaxV > 100 then MaxV := 100;
Result := '';
if Length(SecString) < 16 then Exit;
for i := 1 to Length(SecString) do
begin
s1 := Copy(SecString, i + 1,Length(SecString));
if Pos(SecString[i], s1) > 0 then Exit;
if Pos(SecString[i], CharSet) <= 0 then Exit;
end;
s1 := CharSet;
s2 := '';
for i := 1 to Length(SecString) do
begin
x := Pos(SecString[i], s1);
if x > 0 then s1 := Copy(s1, 1,x - 1) + Copy(s1, x + 1,Length(s1));
end;
ss := SecString;
for i := 1 to Length(Data) do
begin
s2 := s2 + ss[Ord(Data[i]) mod 16 + 1];
ss := Copy(ss, Length(ss), 1) + Copy(ss, 1,Length(ss) - 1);
s2 := s2 + ss[Ord(Data[i]) div 16 + 1];
ss := Copy(ss, Length(ss), 1) + Copy(ss, 1,Length(ss) - 1);
end;
Result := RNDString(s1, Random(MaxV - MinV) + minV + 1);
for i := 1 to Length(s2) do Result := Result + s2[i] + RNDString(s1, Random(MaxV - MinV) + minV);
end;
function Decode(Data, SecString, CharSet: string): string;
var
i, x, x2: integer;
s1, s2, ss: string;
begin
Result := #1;
if Length(SecString) < 16 then Exit;
for i := 1 to Length(SecString) do
begin
s1 := Copy(SecString, i + 1,Length(SecString));
if Pos(SecString[i], s1) > 0 then Exit;
if Pos(SecString[i], CharSet) <= 0 then Exit;
end;
s1 := CharSet;
s2 := '';
ss := SecString;
for i := 1 to Length(Data) do if Pos(Data[i], ss) > 0 then s2 := s2 + Data[i];
Data := s2;
s2 := '';
if Length(Data) mod 2 <> 0 then Exit;
for i := 0 to Length(Data) div 2 - 1 do
begin
x := Pos(Data[i * 2 + 1], ss) - 1;
if x < 0 then Exit;
ss := Copy(ss, Length(ss), 1) + Copy(ss, 1,Length(ss) - 1);
x2 := Pos(Data[i * 2 + 2], ss) - 1;
if x2 < 0 then Exit;
x := x + x2 * 16;
s2 := s2 + chr(x);
ss := Copy(ss, Length(ss), 1) + Copy(ss, 1,Length(ss) - 1);
end;
Result := s2;
end;
So yeah, if anyone could point me in the right direction I would greatly appreciate it.

New Topic/Question
Reply


MultiQuote







|