我通过Internet将数据发送为TmemoryStream,现在我想使用简单的算法对其进行加密。替换TMemoryStream中的字节
所以我想在tmemorystream中替换每个和每个字节来引用它。
看起来像
例如(以字节为单位一个MemoryStream):
[123] [233] [122] [001] [123] [233] [122] [001] [123] [233] [122] [001]
例如(以ASCII密码)
HI = [72] [73]
encription
[123 + 72] [233 + 73] [122 + 72] [001 + 73] [72 123+] [233 + 73] [122 + 72] [001 + 73] [123 + 72] [233 + 73] [122 + 72] [001 + 73]
终值 [195] [51] [194] [74] ...
我如何在使用Delphi的单个解析中做这种替换
和
如何在单个解析中替换memeorystream中的字节以实现此目的。
=======================更新====================== ========================
var pq: integer ;
....
LLine := // from a stream
//start blocjk
//my encription
p := LLine.Memory;
for i := 0 to LLine.Size-1 do
begin
pp := p^ ;
pq := pp + 72 ;
if pq > 255 then
begin
pq := pq - 255 ;
end;
P^ := Byte(pq) ;
inc(p);
end;
// my encription end
//my decription
LLine.Position := 0;
p := LLine.Memory;
for i := 0 to LLine.Size-1 do
begin
pp := p^ ;
pq := pp - 72 ;
if pq < 0 then
begin
pq := pq + 255 ;
end;
P^ := Byte(pq) ;
inc(p);
end;
//end
//end blocjk
Image1.Picture.Graphic.LoadFromStream(LLine);
你会如何分解[233 + 73] - > [51]回到[233 + 73]? – 2012-01-17 11:47:39
@AlexK。你可以从51减去73(73是charowrd中的char)否则它将减少22的255 – VibeeshanRC 2012-01-17 11:55:26
我不喜欢你的算法。更好地使用XOR加密,甚至更好地使用像RC4这样的实际流加密,这很容易实现。 – kobik 2012-01-17 15:31:42