//uses StrUtils;
function RightCopy(S: string; Index, count: Integer): string;
begin
Result := Copy(S,Length(S)-count+1-(Index-1),count);
end;
function jiami(PlainStr, key: string): string;
var
StrChar, Keychar: Char;
Pos: Integer;
i : Integer;
StrLeft, StrRight: String;
begin
Pos := 1;
for i := 1 to Length(PlainStr) do
begin
StrChar := copy(PlainStr, i, 1)[1];
KeyChar := copy(key, Pos, 1)[1];
if ((ord(StrChar) Xor ord(KeyChar)) < 32) Or
((ord(StrChar) Xor ord(KeyChar)) > 126) Or
(ord(StrChar) > 255) Then //ord(StrChar) < 0 永遠(yuǎn)為false 去掉了
Result := Result + StrChar
Else
Result := Result + Char(ord(StrChar) Xor ord(KeyChar));
if Pos = Length(key) then Pos := 0;
Inc(Pos);
end;
If Length(Result) Mod 2 = 0 Then
begin
StrLeft := ReverseString(copy(Result, 0, Round(Length(Result) / 2)));
StrRight := ReverseString(RightCopy(Result, 1, Round(Length(Result) / 2)));
Result := StrLeft + StrRight;
end;
end;
function jiemi(PlainStr, key: string): string;
var
StrLeft, StrRight: string;
num2, i : Integer;
StrChar, Keychar: Char;
begin
num2 := 1;
if Length(PlainStr) mod 2 = 0 then
begin
StrLeft := ReverseString(copy(PlainStr, 0, Round(Length(PlainStr) / 2)));
StrRight := ReverseString(RightCopy(PlainStr, 1,
Round(Length(PlainStr) / 2)));
PlainStr := StrLeft + StrRight;
end;
for i := 1 to Length(PlainStr) do
begin
StrChar := copy(PlainStr, i, 1)[1];
Keychar := copy(key, num2, 1)[1];
if (((((ord(StrChar) Xor ord(Keychar)) < 32) Or ((ord(StrChar) Xor ord(Keychar)) >
126)) ) Or (ord(StrChar) > 255)) then //ord(StrChar) < 0 永遠(yuǎn)為false 去掉了
Result := Result + StrChar
else
Result := Result + Char(ord(StrChar) xor ord(Keychar));
if num2 = Length(key) then num2 := 0;
Inc(num2);
end;
end;