this slowpoke moves

Block File Crypter

function StrToKey(Str : String) : Longint;
var I, J : Longint;
begin
  Result := 0;
  For i := 1 to length(Str) do begin
  J := ord(Str[i]);
  Result := Result +  J;
  end;
end;

procedure FileCrypt(SourceFileName, DestFileName : String; CryptageKey : Longint; Crypt : Boolean);
type
 CryptOpt = record
  ExeSource : String;
  ExeDest : String;
  Key : Longint;
 end;
 CryptUtil = record
  BufOrds : Array[1..2048] of Longint;
  FromF, ToF : File;
  Buf : Array[1..2048] of Char;
  NumRead, NumWritten : Longint;
 end;
var
 CryptOpts : CryptOpt;
 CryptUtils : CryptUtil;
 I : Longint;
begin
 CryptOpts.ExeSource := SourceFileName;
 CryptOpts.ExeDest := DestFileName;
 CryptOpts.Key := CryptageKey;
 Assign(CryptUtils.FromF, CryptOpts.ExeSource);
 Reset(CryptUtils.FromF, 1);
 Assign(CryptUtils.ToF, CryptOpts.ExeDest);
 Rewrite(CryptUtils.ToF, 1);
 Repeat
  BlockRead(CryptUtils.FromF, CryptUtils.Buf, SizeOf(CryptUtils.Buf), CryptUtils.NumRead);
  For i := 1 to 2048 do begin
   CryptUtils.BufOrds[i] := ord(CryptUtils.Buf[i]);
   
   If Crypt = True then 
   CryptUtils.BufOrds[i] := CryptUtils.BufOrds[i] + CryptOpts.Key
   Else 
   CryptUtils.BufOrds[i] := CryptUtils.BufOrds[i] - CryptOpts.Key;
   CryptOpts.Key := CryptOpts.Key + 1;
   CryptUtils.Buf[i] := chr(CryptUtils.BufOrds[i]);
  end;
  BlockWrite(CryptUtils.ToF, CryptUtils.Buf, CryptUtils.NumRead, CryptUtils.NumWritten);
 Until 
 ((CryptUtils.NumRead = 0) or (CryptUtils.NumRead <> CryptUtils.NumWritten));
 Close(CryptUtils.FromF);
 Close(CryptUtils.ToF);
end;
Beispiel :
procedure TForm1.Button1Click(Sender: TObject);
begin
  FileCrypt('no.exe','no1.exe',StrToKey(Edit1.Text),True);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  FileCrypt('no1.exe','no.exe',StrToKey(Edit1.Text),False);
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate