From: "Filsinger, Andreas (Softwareentwicklung)" To: "Filsinger, Andreas (Softwareentwicklung)" ; Subject: Re: Computer Lab Feedback, "Image Encryption" Date: Saturday, December 01, 2001 18:55 Earl, sorry, but take "Rev 1.001": ------------------------------------------------------------------------ var BMPScrambleSeed: integer; procedure BMPScramble(const b: TBitMap; Key: integer); // // (c)'01 by http://www.efg2.com/Lab // // scrambles (encrypt) a bitmap before you save it to // disk (for example) or before post it to a database-field. // Scramble it again before you want to view it. // Ensure to use the same key-value, for each pic, but // different key-values for different pictures. // // // Rev. 1.001 (2001-12-02) Andreas Filsinger, www.cargobay.de // new: "global" var "BMPScrambleSeed" // fix: NextModulu Bug // Rev. 1.000 (2001-12-02) Andreas Filsinger, www.cargobay.de // info: This is my delphi 6.01 Version: There where two reasons // because i rewrite the code. // 1) In the Delphi Help there is a hint, that you should NOT // use "random" to encrypt data, because implementations may // change in future releases. // 2) after "dormat" i accessed the Rows: That caused an Exception // new: only one ScanLine[n] // new: NO random()-call // var i, j: integer; Row: PWordArray; ScanlineBytes: integer; _ScanlineOp: word; function NextModulu : word; asm PUSH EBX XOR EBX, EBX MOV EAX,10000H IMUL EDX,[EBX].BMPScrambleSeed,08088405H INC EDX MOV [EBX].BMPScrambleSeed,EDX MUL EDX MOV EAX,EDX POP EBX end; begin BMPScrambleSeed := Key; with b do begin // Ensure, this is a device independent Bitmap HandleType := bmDIB; // Get the Adress of the first Pixel-Data-Row Row := ScanLine[0]; // Obtain Lenght of one ROW ScanlineBytes := Integer(ScanLine[1]) - Integer(Row); // Obtain Lenght of one, ignore direction, "Count of words" is OK _ScanlineOp := abs(ScanlineBytes) div 2; // for each line for j := 0 to pred(Height) do begin // for each pixel-data-word for i := 0 to pred(_ScanlineOp) do Row[i] := Row[i] xor NextModulu; // theres no need to call ScanLine[] again inc(Integer(Row), ScanlineBytes); end; end; end; ... ----------------------------------------------------------------- Thanks. Andreas Filsinger _______________________________________________________ / Tel. +49 7251 966100 | Andreas Filsinger \ | Mob. +49 175 5913758 | Softwareentwicklung | | Fax. +49 7251 966101 | Stettfelder Strasse 44 | | mailto:Andreas@Filsinger.de | 76698 Ubstadt | | http://www.CargoBay.de | GERMANY | \_______________________________________________________/