Ads 468x60px

Smaller time frame always follow the bigger time frame. It's better wait be patience to enter in position than risk with BIG SL. Having strong trading discipline and taking losses when necessary is a sign of serious trading approach
Subscribe:

Labels

Friday, June 8, 2012

File Encrypt / Decrypt

Encryption is the process of converting a file into a format that cannot be read by the applications set up to open the file. To remove the encryption you decrypt.
To encrypt or decrypt a file, simply click on the "Open" button, select an integer "masking" value and then click "(En/De) Crypt File". This little tool is ideal for offices that need to keep important documents secure.




unit UnitEnDecrypt;

interface

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

type
  TEnDeCrypt = class(TForm)
    OpenDialog1: TOpenDialog;
    BtnOpen: TBitBtn;
    BtnEnDe: TBitBtn;
    GroupBox1: TGroupBox;
    Memo1: TMemo;
    GroupBox2: TGroupBox;
    leKey: TLabeledEdit;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    procedure BtnOpenClick(Sender: TObject);
    procedure BtnEnDeClick(Sender: TObject);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private declarations }
    procedure EnDecryptFile(pathin, pathout: string; Chave: Word);
  public
    { Public declarations }
  end;

var
  EnDeCrypt: TEnDeCrypt;

implementation

{$R *.dfm}

procedure TEnDeCrypt.EnDecryptFile(pathin, pathout: string; Chave: Word);
var
  InMS, OutMS: TMemoryStream;
  cnt: Integer;
  C: byte;
begin
  InMS  := TMemoryStream.Create;
  OutMS := TMemoryStream.Create;
  try
    InMS.LoadFromFile(pathin);
    InMS.Position := 0;
    for cnt := 0 to InMS.Size - 1 DO
      begin
        InMS.Read(C, 1);
        C := (C xor not (ord(chave shr cnt)));
        OutMS.Write(C, 1);
      end;
    OutMS.SaveToFile(pathout);
  finally
    InMS.Free;
    OutMS.Free;
  end;
end;

procedure TEnDeCrypt.BtnOpenClick(Sender: TObject);
begin
  OpenDialog1.Execute;
end;

procedure TEnDeCrypt.BtnEnDeClick(Sender: TObject);
begin
  IF MessageDlg('ATTENTION'+#13+
                'Do not miss the password, or lose the file!',
                mtConfirmation, [mbYes, mbNo], 0) = mrYes THEN
    BEGIN
      EnDecryptFile(OpenDialog1.FileName, OpenDialog1.FileName, StrToInt(leKey.Text));
      ShowMessage('Operation completed successfully!');
    END;
end;

procedure TEnDeCrypt.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  aux: integer;
begin
  IF GroupBox1.Height = 83 THEN
    BEGIN
      FOR aux := 83 DOWNTO 18 DO
        GroupBox1.Height := aux;
    END;
end;

end.

Source

comments