Ya solo nos queda aplicar otra vuelta de tuerca, y limitar el cifrado a un recuadro de la imagen, por ejemplo, para taparle la cara a alguien en una foto:
Código Delphi
[-]
type
Triple = array[1..3]of Byte;
procedure Cifrar(Imagen: TPicture; R: TRect; Clave: Longint);
var
Bitmap: TBitmap;
P1, P2: ^Triple;
i, j, k, H, W: Integer;
Temp: Triple;
Sec: Array of Integer;
begin
RandSeed:= Clave;
if not (Imagen.Graphic is TBitmap) then
begin
Bitmap:= TBitmap.Create;
try
Bitmap.Width:= Imagen.Width;
Bitmap.Height:= Imagen.Height;
Bitmap.Canvas.Draw(0,0,Imagen.Graphic);
Imagen.Assign(Bitmap);
finally
Bitmap.Free;
end;
end;
Imagen.Bitmap.PixelFormat:= pf24bit;
IntersectRect(R,R,Rect(0,0,Imagen.Bitmap.Width - 1,Imagen.Bitmap.Height - 1));
H:= R.Bottom - R.Top;
W:= R.Right - R.Left;
SetLength(Sec,H div 2);
for i:= 0 to High(Sec) do
Sec[i]:= Length(Sec) + i;
for i:= 0 to High(Sec) do
begin
k:= Sec[i];
j:= Random(High(Sec));
Sec[i]:= Sec[j];
Sec[j]:= k;
end;
for j:= 0 to High(Sec) do
begin
P1:= Imagen.Bitmap.ScanLine[R.Top + j];
P2:= Imagen.Bitmap.ScanLine[R.Top + Sec[j]];
inc(P1,R.Left);
inc(P2,R.Left);
for i:= 0 to W - 1 do
begin
Temp:= P1^;
P1^:= P2^;
P2^:= Temp;
inc(P1); inc(P2);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Cifrar(Image1.Picture,Rect(100,100,200,200),1978);
Image1.Refresh;
end;
Bueno, por ahora no se me ocurre nada mas, el siguiente paso seria aplicar algoritmos de criptografía fuerte (AES, Serpent, ...) para cifrar los puntos de la imagen en vez de usar un simple Random.
Roman, ya me contaras si esto se ajusta a lo que buscabas, estabas pensando en otra cosa o incluso si necesitas ir mas allá.