Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2005.01.30;
Скачать: CL | DM;

Вниз

Word шифровка   Найти похожие ветки 

 
Silver   (2004-04-17 06:32) [0]

Здравствуйте.
Помогите пожайлуста как шифрануть Word"овский файл. Тоесть надо сделать так зашифровать его , а потом в Delphi через оле открыть уже расшифрованным.
Делаю так ничего толкового неполучается.

unit EncodStr;

interface

uses
 Classes;

type
 TEncodedStream = class (TFileStream)
 private
   FKey: Char;
 public
   constructor Create(const FileName: string; Mode: Word);
   function Read(var Buffer; Count: Longint): Longint; override;
   function Write(const Buffer; Count: Longint): Longint; override;
   property Key: Char read FKey write FKey default "A";
 end;

implementation

constructor TEncodedStream.Create(
 const FileName: string; Mode: Word);
begin
 inherited Create (FileName, Mode);
 FKey := "A";
end;

function TEncodedStream.Write(const Buffer;
  Count: Longint): Longint;
var
 pBuf, pEnc: PChar;
 I, EncVal: Integer;
begin
 // allocate memory for the encoded buffer
 GetMem (pEnc, Count);
 try
   // use the buffer as an array of characters
   pBuf := PChar (@Buffer);
   // for every character of the buffer
   for I := 0 to Count - 1 do
   begin
     // encode the value and store it
     EncVal := ( Ord (pBuf[I]) + Ord(Key) ) mod 256;
     pEnc [I] := Chr (EncVal);
   end;
   // write the encoded buffer to the file
   Result := inherited Write (pEnc^, Count);
 finally
   FreeMem (pEnc, Count);
 end;
end;

function TEncodedStream.Read(var Buffer; Count: Longint): Longint;
var
 pBuf, pEnc: PChar;
 I, CountRead, EncVal: Integer;
begin
 // allocate memory for the encoded buffer
 GetMem (pEnc, Count);
 try
   // read the encoded buffer from the file
   CountRead := inherited Read (pEnc^, Count);
   // use the output buffer as a string
   pBuf := PChar (@Buffer);
   // for every character actually read
   for I := 0 to CountRead - 1 do
   begin
     // decode the value and store it
     EncVal := ( Ord (pEnc[I]) - Ord(Key) ) mod 256;
     pBuf [I] := Chr (EncVal);
   end;
 finally
   FreeMem (pEnc, Count);
 end;
 // return the number of characters read
 Result := CountRead;
end;

end.


unit EncForm;

interface

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

type
 TFormEncode = class(TForm)
   Memo1: TMemo;
   Memo2: TMemo;
   OpenDialog1: TOpenDialog;
   SaveDialog1: TSaveDialog;
   Panel1: TPanel;
   BtnLoadPlain: TButton;
   BtnSaveEncoded: TButton;
   BtnLoadEncoded: TButton;
   Splitter1: TSplitter;
   procedure BtnSaveEncodedClick(Sender: TObject);
   procedure BtnLoadEncodedClick(Sender: TObject);
   procedure BtnLoadPlainClick(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
 end;

var
 FormEncode: TFormEncode;

implementation

{$R *.DFM}

uses
 EncodStr;

procedure TFormEncode.BtnSaveEncodedClick(Sender: TObject);
var
 EncStr: TEncodedStream;
begin
 if SaveDialog1.Execute then
 begin
   EncStr := TEncodedStream.Create(
     SaveDialog1.Filename, fmCreate);
   try
     Memo1.Lines.SaveToStream (EncStr);
   finally
     EncStr.Free;
   end;
 end;
end;

procedure TFormEncode.BtnLoadEncodedClick(Sender: TObject);
var
 EncStr: TEncodedStream;
begin
 if OpenDialog1.Execute then
 begin
   EncStr := TEncodedStream.Create(
     OpenDialog1.FileName, fmOpenRead);
   try
     Memo2.Lines.LoadFromStream (EncStr);
   finally
     EncStr.Free;
   end;
 end;
end;

procedure TFormEncode.BtnLoadPlainClick(Sender: TObject);
begin
 if OpenDialog1.Execute then
   Memo1.Lines.LoadFromFile (
     OpenDialog1.FileName);
end;

end.


Да и есчеё кто знает как при момощи Delphi открыть вордовский файл, что бы на форме отображалась только стараница безовсяких панелей инструментов.

Испльзую Delphi 7.

Заранее спасибо.


 
VMcL ©   (2004-04-17 14:57) [1]

>как при момощи Delphi открыть вордовский файл, что бы на форме отображалась только стараница

TOleContainer
?


 
Silver   (2004-04-17 18:40) [2]

А как шифрануть Вордовский файл?????????????



Страницы: 1 вся ветка

Текущий архив: 2005.01.30;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.031 c
1-1106132278
denis24
2005-01-19 13:57
2005.01.30
закрытие формы по ESC


6-1099904771
alexb_1
2004-11-08 12:06
2005.01.30
Исходник download-менеджера


1-1105693275
Nad89
2005-01-14 12:01
2005.01.30
Тип данных типа string


10-1082218425
Karbo
2004-04-17 20:13
2005.01.30
Как избавиться от сообщений Excel при закрытии Workbooks ?


14-1105486256
DeadMeat
2005-01-12 02:30
2005.01.30
Все те же грабли...