|
|
ru.algorithms- RU.ALGORITHMS ---------------------------------------------------------------- From : Viktor Karev 2:5020/400 11 Oct 2001 20:17:36 To : Vadim Goncharov Subject : Re: DES-3 -------------------------------------------------------------------------------- Окончание. var NewKey: string; procedure SetNewKey; begin if PKey+7<=Len then begin NewKey:=Copy(Key,Pkey,8); inc(Pkey,8); end else begin NewKey:=Copy(Key,PKey,8)+Copy(Key,1,PKey+7-Len); inc(PKey,8-Len); end; InitKey(PDataBlock(@NewKey[1])^); end; procedure SetKey(S: string); begin Key:=S; Len:=length(S); if Len<8 then Halt(1); PKey:=1; SetNewKey; end; procedure Encode(InBlock: TDataBlock; var OutBlock: TDataBlock); begin R:=KE; DoDes(InBlock,OutBlock); end; procedure Decode(InBlock: TDataBlock; var OutBlock: TDataBlock); begin R:=KD; DoDes(InBlock,OutBlock); end; procedure EncodeText(InS: string; var OutS: string); var i,j,l: integer; S: TDataBlock; begin i:=1; l:=Length(InS); OutS[0]:=InS[0]; while i*8-7<=l do begin Move(InS[i*8-7],S,8); if i*8>L then for j:=(l mod 8)+1 to 8 do S[j]:=0; Encode(S,S); Move(S,OutS[i*8-7],8); OutS[0]:=char(i*8); inc(i); SetNewKey; end; end; procedure DecodeText(InS: string; var OutS: string); var i,j,l: integer; S: TDataBlock; begin i:=1; l:=Length(InS); OutS[0]:=InS[0]; while i*8-7<=l do begin Move(InS[i*8-7],S,8); if i*8>L then for j:=(l mod 8)+1 to 8 do S[j]:=0; Decode(S,S); if i*8<=L then Move(S,OutS[i*8-7],8) else Move(S,OutS[i*8-7],L-(i-1)*8); inc(i); SetNewKey; end; end; begin InitDes; end. --- ifmail v.2.15dev5 * Origin: Black Jack House (2:5020/400) Вернуться к списку тем, сортированных по: возрастание даты уменьшение даты тема автор
Архивное /ru.algorithms/657789c6917a.html, оценка из 5, голосов 10
|