Ver Mensaje Individual
  #10  
Antiguo 01-10-2013
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Reputación: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
danielmj,

Cita:
Empezado por danielmj
...encontré esta unidad en la pagina de Seoane (Calcular hash md5)...
Revisa este código:
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ClipBrd, StrUtils, ComCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Edit1: TEdit;
    ProgressBar1: TProgressBar;
    Timer1: TTimer;
    Label1: TLabel;
    Label2: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses Hashes; // Implementa la unidad de cálculo de Hash Md5 de Seoane http://delphi.jmrds.com/?q=node/11

// Inicialización de componentes.
procedure TForm1.FormCreate(Sender: TObject);
begin
   ProgressBar1.Min := 1;
   ProgressBar1.Max := 100;
   Timer1.Interval := 100;
   Timer1.Enabled := False;
   Label1.Visible := False;
end;

// Control Visual de Ejecución del Hash MD5 de un Archivo
procedure TForm1.Timer1Timer(Sender: TObject);
begin

   if ProgressBar1.Position = 100 then
      ProgressBar1.Position := 0;

   ProgressBar1.StepBy(1);

end;

// Cálculo del Hash MD5 de un Archivo (No importa el tamaño)
procedure TForm1.Button1Click(Sender: TObject);
var
   openDialog : TOpenDialog;
   AuxStr : String;
   TI, TF: TDateTime;
   Hour, Min, Sec, MSec: Word;
   MsgTime : String;

begin

   openDialog := TOpenDialog.Create(self);
   openDialog.InitialDir := GetCurrentDir;
   openDialog.Options := [ofFileMustExist];
   openDialog.Filter := 'All Files|*.*|';
   openDialog.FilterIndex := 1;

   if openDialog.Execute then
   begin

      Timer1.Enabled := True;
      Label1.Visible := True;
      Button1.Enabled := False;
      Button2.Enabled := False;
      Button3.Enabled := False;

      TI := Now;
      AuxStr := 'MD5 de ' + openDialog.FileName + ' = ' + CheckSum(openDialog.FileName);
      TF := Now - TI;
      DecodeTime(TF, Hour, Min, Sec, MSec);

      ListBox1.Items.Add(AuxStr);
      if ListBox1.ScrollWidth < ListBox1.Canvas.TextWidth(AuxStr) then
         ListBox1.ScrollWidth := ListBox1.Canvas.TextWidth(AuxStr) + 120;

      Timer1.Enabled := False;
      ProgressBar1.Position := 0;
      Label1.Visible := False;
      Button1.Enabled := True;
      Button2.Enabled := True;
      Button3.Enabled := True;

      MsgTime := Format('Tiempo de cálculo de MD5 %.2d:%.2d:%.2d:%.3d',[Hour,Min,Sec,MSec]);
      MessageDlg(MsgTime,mtinformation,[mbok],0);

   end
   else
      ShowMessage('No se seleciono ningún archivo para cálculo de MD5');

   openDialog.Free;

end;

// Cálculo del Hash MD5 de un String
procedure TForm1.Button2Click(Sender: TObject);
var
   AuxStr : String;

begin

   AuxStr := 'MD5 de ' + Edit1.Text + ' = ' + StrCheckSum(Edit1.Text);
   ListBox1.Items.Add(AuxStr);
   if ListBox1.ScrollWidth < ListBox1.Canvas.TextWidth(AuxStr) then
      ListBox1.ScrollWidth := ListBox1.Canvas.TextWidth(AuxStr) + 120;

end;

// Resetea el Form
procedure TForm1.Button3Click(Sender: TObject);
begin
   ListBox1.Clear;
   Edit1.Text := EmptyStr;
end;

// Copia Hash MD5 a Clipboard
procedure TForm1.ListBox1Click(Sender: TObject);
begin
   Clipboard.AsText := AnsiRightStr(ListBox1.Items.Strings[ListBox1.ItemIndex],32);
end;

end.
El código anterior es una implementación de la rutina de Calcular hash md5 de la Web de Seoane, como se muestra en la siguiente imagen:



El ejemplo esta disponible en el siguiente link: http://terawiki.clubdelphi.com/Delph...wnload=MD5.rar

Espero sea útil

Nelson
Responder Con Cita