Advertisement
ViciadoEmLinux1987

Criptografador

Mar 11th, 2023
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.38 KB | None | 0 0
  1. unit Unit1;
  2.    
  3.     {$mode objfpc}{$H+}
  4.    
  5.     interface
  6.    
  7.     uses
  8.    
  9.       Classes, SysUtils, FileUtil, Forms,
  10.    
  11.     Controls, Graphics, Dialogs, StdCtrls;
  12.    
  13.     type
  14.    
  15.       { TForm1 }
  16.    
  17.       TForm1 = class(TForm)
  18.    
  19.         Button1: TButton;
  20.    
  21.         Button2: TButton;
  22.    
  23.         edtcriptografado: TEdit;
  24.    
  25.         edttexto: TEdit;
  26.    
  27.         edtdescriptografado: TEdit;
  28.    
  29.         edtkey: TEdit;
  30.    
  31.         Label1: TLabel;
  32.    
  33.         Label2: TLabel;
  34.    
  35.         Label3: TLabel;
  36.    
  37.         Label4: TLabel;
  38.    
  39.         procedure Button1Click(Sender: TObject);
  40.    
  41.         procedure Button2Click(Sender: TObject);
  42.    
  43.         procedure FormCreate(Sender: TObject);
  44.    
  45.       private
  46.    
  47.        function criptografar(const key, texto:String):String;
  48.    
  49.        function descriptografar(const key, texto:String):String;
  50.    
  51.       public
  52.    
  53.       end;
  54.    
  55.     var
  56.    
  57.       Form1: TForm1;
  58.    
  59.     implementation
  60.    
  61.    
  62.     {$R *.lfm}
  63.    
  64.    
  65.     { TForm1 }
  66.    
  67.    
  68.     procedure TForm1.Button1Click(Sender: TObject);
  69.    
  70.     begin
  71.    
  72.      edtcriptografado.Text:=criptografar(edtkey.Text,edttexto.Text);
  73.    
  74.     end;
  75.    
  76.     procedure TForm1.Button2Click(Sender: TObject);
  77.    
  78.     begin
  79.    
  80.      edtdescriptografado.Text:=descriptografar(edtkey.Text,
  81.    
  82.     edtcriptografado.Text);
  83.    
  84.     end;
  85.    
  86.     function TForm1.criptografar(const key, texto: String): String;
  87.    
  88.     var
  89.    
  90.       I: Integer;
  91.    
  92.       C: Byte;
  93.    
  94.     begin
  95.    
  96.       Result := '';
  97.    
  98.       for I := 1 to Length(texto) do begin
  99.    
  100.         if Length(Key) > 0 then
  101.    
  102.           C := Byte(Key[1 + ((I - 1) mod Length(Key))]) xor Byte(texto[I])
  103.    
  104.         else
  105.    
  106.           C := Byte(texto[I]);
  107.    
  108.         Result := Result + AnsiLowerCase(IntToHex(C, 2));
  109.    
  110.       end;
  111.    
  112.    
  113.     end;
  114.    
  115.    
  116.     function TForm1.descriptografar(const key, texto: String): String;
  117.    
  118.     var
  119.    
  120.       I: Integer;
  121.    
  122.       C: Char;
  123.    
  124.    
  125.     begin
  126.    
  127.       Result := '';
  128.    
  129.       for I := 0 to Length(texto) div 2 - 1 do begin
  130.    
  131.         C := Chr(StrToIntDef('$' + Copy(texto, (I * 2) + 1, 2), Ord(' ')));
  132.    
  133.         if Length(Key) > 0 then
  134.    
  135.           C := Chr(Byte(Key[1 + (I mod Length(Key))]) xor Byte(C));
  136.    
  137.         Result := Result + C;
  138.    
  139.       end;
  140.    
  141.     end;
  142.    
  143.    
  144.     end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement