M
moroko
Unregistered / Unconfirmed
GUEST, unregistred user!
下面是两个两个解码函数为什么出错的地方都一样呢?有点搞不明白了!
function TForm1.ReturnHex(Value: Integer): Integer;
begin
case Value of
0: Value := $7f;
1: Value := $3f;
2: Value := $1f;
3: Value := $0f;
4: Value := $07;
5: Value := $03;
6: Value := $01;
7: Value := $00;
end;
Result := Value;
end;
function TForm1.DecodeEnglish(InputStr: string): string;
var
InStr: array [0..300] of Byte;
OutStr: array [0..300] of Char;
str: string;
i, j, Point, temp: Integer;
begin
i := 0; j := 0;
Point := 0;
FillChar(InStr, 301, #0);
FillChar(OutStr, 301, #0);
for i := 0 to Length(InputStr) - 1 do begin
if Odd(i) then Continue;
str := '0x' + Copy(InputStr, i+1, 2);
InStr[i div 2] := StrToInt(str);
end;
i := 0;
while (j <= Length(InputStr) div 2) do begin
if Point = 0 then
OutStr := Chr(InStr[j] and ReturnHex(Point))
else
OutStr := Chr(((InStr[j] and ReturnHex(Point)) shl Point) or (InStr[j-1] shr (8-Point)));
if (Point mod 7 = 0) and (Point <> 0) then
Point := 0
else
Point := Point + 1;
i := i + 1;
j := i - (i div 8);
end;
OutStr[12] := Chr(((InStr[12] and $07) shl 5) or (InStr[11] shr (8-5)));
Result := AnsiString(OutStr);
end;
//============================================================================
edit1.Text:=DecodeEnglish('B1582C168BC562B1582C168BC562B1180000');
edit1的结果应该是111111111111111111可却变成111111111111?1111
下面的函数得到结果一样
function TForm1.EnglishDecode(const S: string): string;
const
HHex: array [0..7] of Byte = ($7F, $3F, $1F, $0F, $07, $03, $01, $00);
var
I, J, Point, Size: Integer;
InStr: array [0..300] of Byte;
begin
FillChar(InStr, SizeOf(InStr), 0);
Result := StringOfChar(#0, 300);
I := 0;
Size := Length(S);
while Size > 0 do
begin
InStr[I div 2] := StrToInt('$' + S[I + 1] + S[I + 2]);
Inc(I, 2);
Dec(Size, 2);
end;
I := 0;
J := 0;
Point := 0;
Size := Length(S) div 2;
while J <= Size do
begin
if Point = 0 then
Result[I + 1] := Chr(InStr[J] and HHex[Point])
else
Result[I + 1] := Chr(((InStr[J] and HHex[Point]) shl Point) or (InStr[J-1] shr (8 - Point)));
if ((Point mod 7) = 0) and (Point <> 0) then
Point := 0
else
Inc(Point);
Inc(I);
J := I - (I div 8);
end;
Result[13] := Chr(((InStr[12] and $07) shl 5) or (InStr[11] shr (8 - 5)));
end;
//==============================================================================
edit1.Text:=EnglishDecode('B1582C168BC562B1582C168BC562B1180000');
这是为什么呢,有什么办法解决吗?
function TForm1.ReturnHex(Value: Integer): Integer;
begin
case Value of
0: Value := $7f;
1: Value := $3f;
2: Value := $1f;
3: Value := $0f;
4: Value := $07;
5: Value := $03;
6: Value := $01;
7: Value := $00;
end;
Result := Value;
end;
function TForm1.DecodeEnglish(InputStr: string): string;
var
InStr: array [0..300] of Byte;
OutStr: array [0..300] of Char;
str: string;
i, j, Point, temp: Integer;
begin
i := 0; j := 0;
Point := 0;
FillChar(InStr, 301, #0);
FillChar(OutStr, 301, #0);
for i := 0 to Length(InputStr) - 1 do begin
if Odd(i) then Continue;
str := '0x' + Copy(InputStr, i+1, 2);
InStr[i div 2] := StrToInt(str);
end;
i := 0;
while (j <= Length(InputStr) div 2) do begin
if Point = 0 then
OutStr := Chr(InStr[j] and ReturnHex(Point))
else
OutStr := Chr(((InStr[j] and ReturnHex(Point)) shl Point) or (InStr[j-1] shr (8-Point)));
if (Point mod 7 = 0) and (Point <> 0) then
Point := 0
else
Point := Point + 1;
i := i + 1;
j := i - (i div 8);
end;
OutStr[12] := Chr(((InStr[12] and $07) shl 5) or (InStr[11] shr (8-5)));
Result := AnsiString(OutStr);
end;
//============================================================================
edit1.Text:=DecodeEnglish('B1582C168BC562B1582C168BC562B1180000');
edit1的结果应该是111111111111111111可却变成111111111111?1111
下面的函数得到结果一样
function TForm1.EnglishDecode(const S: string): string;
const
HHex: array [0..7] of Byte = ($7F, $3F, $1F, $0F, $07, $03, $01, $00);
var
I, J, Point, Size: Integer;
InStr: array [0..300] of Byte;
begin
FillChar(InStr, SizeOf(InStr), 0);
Result := StringOfChar(#0, 300);
I := 0;
Size := Length(S);
while Size > 0 do
begin
InStr[I div 2] := StrToInt('$' + S[I + 1] + S[I + 2]);
Inc(I, 2);
Dec(Size, 2);
end;
I := 0;
J := 0;
Point := 0;
Size := Length(S) div 2;
while J <= Size do
begin
if Point = 0 then
Result[I + 1] := Chr(InStr[J] and HHex[Point])
else
Result[I + 1] := Chr(((InStr[J] and HHex[Point]) shl Point) or (InStr[J-1] shr (8 - Point)));
if ((Point mod 7) = 0) and (Point <> 0) then
Point := 0
else
Inc(Point);
Inc(I);
J := I - (I div 8);
end;
Result[13] := Chr(((InStr[12] and $07) shl 5) or (InStr[11] shr (8 - 5)));
end;
//==============================================================================
edit1.Text:=EnglishDecode('B1582C168BC562B1582C168BC562B1180000');
这是为什么呢,有什么办法解决吗?