L
liaotw
Unregistered / Unconfirmed
GUEST, unregistred user!
我在将二进制信息以字符串信息进行保存时,为了避免特殊二进制符号造成字符串错误的
情况,首先将二进制信息进行了Base64编码方式调制,然后在保存调制后的信息。在需要
使用二进制信息的场合,首先传递此经过调制的文本(字符串)信息,然后解调,得到需
要的二进制信息。
下面是我的部分实验代码,在执行时不能达到要求,那位师兄帮忙看看,多谢了!
先需要
Uses EncdDecd
procedure TForm1.Button1Click(Sender: TObject);
var
s1, s2, s3 : string;
memStream, outStream : TMemoryStream;
arr : array of Byte;
arrOut : array of Byte;
b : Byte;
i : Integer;
begin
s1 := Edit1.Text;
SetLength(arr, Length(s1)+1);
for i:=1 to Length(s1) do
begin
if (i mod 16)=0 then
b := KEYSEED[16]
else
b := KEYSEED[i mod 16];
arr[i-1] := b xor Ord(s1);
end;
memStream := TMemoryStream.Create;
outStream := TMemoryStream.Create;
memStream.WriteBuffer(arr[0], Length(arr));
outStream.SetSize(((Length(arr)*8) div 7)+1);
EncodeStream(memStream, outStream);
ZeroMemory(@arr[0], Length(arr));
SetLength(arrOut, Integer(outStream.Size));
outStream.ReadBuffer(arrOut[0], Length(arrOut));
for i:=0 to Length(arrOut)-1 do
begin
s2 := s2 + Char(arrOut);
end;
Edit2.Text := s2;
memStream.SetSize(Length(arr)+1);
DecodeStream(outStream, memStream);
SetLength(arr, Integer(memStream.Size));
memStream.ReadBuffer(arr[0], Length(arr)); //执行异常
for i:=0 to Length(arr) do
begin
s3 := s3+Char(arr);
end;
Edit3.Text:=s3;
end;
情况,首先将二进制信息进行了Base64编码方式调制,然后在保存调制后的信息。在需要
使用二进制信息的场合,首先传递此经过调制的文本(字符串)信息,然后解调,得到需
要的二进制信息。
下面是我的部分实验代码,在执行时不能达到要求,那位师兄帮忙看看,多谢了!
先需要
Uses EncdDecd
procedure TForm1.Button1Click(Sender: TObject);
var
s1, s2, s3 : string;
memStream, outStream : TMemoryStream;
arr : array of Byte;
arrOut : array of Byte;
b : Byte;
i : Integer;
begin
s1 := Edit1.Text;
SetLength(arr, Length(s1)+1);
for i:=1 to Length(s1) do
begin
if (i mod 16)=0 then
b := KEYSEED[16]
else
b := KEYSEED[i mod 16];
arr[i-1] := b xor Ord(s1);
end;
memStream := TMemoryStream.Create;
outStream := TMemoryStream.Create;
memStream.WriteBuffer(arr[0], Length(arr));
outStream.SetSize(((Length(arr)*8) div 7)+1);
EncodeStream(memStream, outStream);
ZeroMemory(@arr[0], Length(arr));
SetLength(arrOut, Integer(outStream.Size));
outStream.ReadBuffer(arrOut[0], Length(arrOut));
for i:=0 to Length(arrOut)-1 do
begin
s2 := s2 + Char(arrOut);
end;
Edit2.Text := s2;
memStream.SetSize(Length(arr)+1);
DecodeStream(outStream, memStream);
SetLength(arr, Integer(memStream.Size));
memStream.ReadBuffer(arr[0], Length(arr)); //执行异常
for i:=0 to Length(arr) do
begin
s3 := s3+Char(arr);
end;
Edit3.Text:=s3;
end;