Unconfigured Ad Widget

Collapse

Anúncio

Collapse
No announcement yet.

Código fonte (Criptografador)

Collapse
X
 
  • Filter
  • Tempo
  • Show
Clear All
new posts

  • Font Size
    #1

    Delphi Código fonte (Criptografador)

    Código:
    unit Unit1;
     
    {$mode objfpc}{$H+}
     
    interface
     
    uses
     
      Classes, SysUtils, FileUtil, Forms, 
     
    Controls, Graphics, Dialogs, StdCtrls;
     
    type
     
      { TForm1 }
     
      TForm1 = class(TForm)
     
        Button1: TButton;
     
        Button2: TButton;
     
        edtcriptografado: TEdit;
     
        edttexto: TEdit;
     
        edtdescriptografado: TEdit;
     
        edtkey: TEdit;
     
        Label1: TLabel;
     
        Label2: TLabel;
     
        Label3: TLabel;
     
        Label4: TLabel;
     
        procedure Button1Click(Sender: TObject);
     
        procedure Button2Click(Sender: TObject);
     
        procedure FormCreate(Sender: TObject);
     
      private
     
       function criptografar(const key, texto:String):String;
     
       function descriptografar(const key, texto:String):String;
     
      public
     
      end;
     
    var
     
      Form1: TForm1;
     
    implementation
     
     
    {$R *.lfm}
     
     
    { TForm1 }
     
     
    procedure TForm1.Button1Click(Sender: TObject);
     
    begin
     
     edtcriptografado.Text:=criptografar(edtkey.Text,edttexto.Text);
     
    end;
     
    procedure TForm1.Button2Click(Sender: TObject);
     
    begin
     
     edtdescriptografado.Text:=descriptografar(edtkey.Text, 
     
    edtcriptografado.Text);
     
    end;
     
    function TForm1.criptografar(const key, texto: String): String;
     
    var
     
      I: Integer;
     
      C: Byte;
     
    begin
     
      Result := '';
     
      for I := 1 to Length(texto) do begin
     
        if Length(Key) > 0 then
     
          C := Byte(Key[1 + ((I - 1) mod Length(Key))]) xor Byte(texto[I])
     
        else
     
          C := Byte(texto[I]);
     
        Result := Result + AnsiLowerCase(IntToHex(C, 2));
     
      end;
     
     
    end;
     
     
    function TForm1.descriptografar(const key, texto: String): String;
     
    var
     
      I: Integer;
     
      C: Char;
     
     
    begin
     
      Result := '';
     
      for I := 0 to Length(texto) div 2 - 1 do begin
     
        C := Chr(StrToIntDef('$' + Copy(texto, (I * 2) + 1, 2), Ord(' ')));
     
        if Length(Key) > 0 then
     
          C := Chr(Byte(Key[1 + (I mod Length(Key))]) xor Byte(C));
     
        Result := Result + C;
     
      end;
     
    end;
     
     
    end.
    Similar Threads
X
Working...
X