Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 17.10.06 18:32 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.OverwriteFile(Filename: string; number: integer;);
var stream: TFilestream; i,zahl: integer;
begin
  stream := TFilestream.Create(filename,fmOpenWrite);
  randomize;
  for i := 1 to number do
  begin
     zahl := random(1);
     stream.Write(zahl,SizeOf(zahl))
  end;
  FreeAndNil(stream);
end;

Habe für ein Programm diesen Algorithmus gschrieben. Er soll eine Datei unleserlich machen. Wenn man eine Datei unter Windows löscht, kann man sie ja normalerweise leicht wiederherstellen. Diese Prozedur soll so eine Datei mit Zufallsdaten überschreiben.
Was haltet ihr von ihr? Optimierungen? Ist das so Quatsch?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 17.10.06 18:38 
Moin!

Wenn "number" die Menge in Bytes sein soll, fliegt dir das um die Ohren bzw. schreibt die 4fache Datenmenge. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Horst_H
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1654
Erhaltene Danke: 244

WIN10,PuppyLinux
FreePascal,Lazarus
BeitragVerfasst: Di 17.10.06 18:58 
Hallo,

random(1) ist immer 0
Lieber random(256*256) und eine 2-Byte Wert fuer Zahl benutzen.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.OverwriteFile(Filename: string; number: integer;); 
var stream: TFilestream; i: integer;zahl:word; 
begin 
  stream := TFilestream.Create(filename,fmOpenWrite); 
  randomize; 
  for i := 1 to number do 
  begin 
     zahl := random(256*256); 
     stream.Write(@zahl,SizeOf(zahl)) 
  end
  FreeAndNil(stream); 
end;

Ausserdem darf number nicht größer als die Dateigröße/2 sein, wie Narses schon sagte.
Muss ich mal testen.

Gruss Horst
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 17.10.06 19:47 
Siehe hier: www.delphipraxis.net...umlberschreiben.html

@Horst_H: Und was ist der Unterschied zu 65536 außer dass du den Rechner noch unnötig mit einer Fließkommamultiplikation beschäftigst?
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 17.10.06 20:59 
Warum denn einen 2-Byte-Wert nehmen?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Horst_H
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1654
Erhaltene Danke: 244

WIN10,PuppyLinux
FreePascal,Lazarus
BeitragVerfasst: Di 17.10.06 21:20 
Hallo,

@Luckie:
wo ist da eine Fliesskommarechnung? Da wird doch vom Compiler ohnehin die Konstante zusammengefasst.

@Marco:
Weil der nur integer Zahlen von 0..2^31-1 ohne die negativen Zahlen erzeugt werden, also waere Bit 31(0..31) immer 0 und nicht zufällig.

Gruss Horst
Einloggen, um Attachments anzusehen!
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 17.10.06 21:24 
Und warum steht bei dir vor zahl ein @?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Horst_H
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1654
Erhaltene Danke: 244

WIN10,PuppyLinux
FreePascal,Lazarus
BeitragVerfasst: Di 17.10.06 21:31 
Hallo,

weil es falsch ist ;-)

Gruss Horst