Hide

The next demonstration of bitmap files shows how easy it is to hide a few bytes of secret information (in this case a date) in a graphics file. Program Show reveals the date. Make sure that you run program Hide before program Show. Store both programs and a copy of london_eye.bmp in the same folder.

program Hide;
  {$APPTYPE CONSOLE}
uses
  SysUtils;
const
  TEXT_TO_HIDE = '20101231';
  HIDE_POSITION = 149;
var
  Picture : file of byte;
  Count : integer;
  CurrentChar : char;
  CurrentCode : byte;
begin
  assignFile(Picture, 'london_eye.bmp');
  reset(Picture);
  for Count := 1 to length(TEXT_TO_HIDE) do
    begin
       seek(Picture, Count * HIDE_POSITION);
       CurrentChar := TEXT_TO_HIDE[Count];
       CurrentCode := ord(CurrentChar);
       write(Picture, CurrentCode);
    end;
  closeFile(Picture);
  write('Text has been hidden in picture. ');
  readln;
end.

program Show;
{$APPTYPE CONSOLE}
uses
  SysUtils;
const
  HIDE_POSITION = 149;
var
  Picture : file of byte;
  Count : integer;
  CurrentChar : char;
  CurrentCode : byte;
  HiddenString : string;
begin
  HiddenString := '';
  assignFile(Picture, 'london_eye.bmp');
  reset(Picture);
  for Count := 1 to 8 do
    begin
       seek(Picture, Count * HIDE_POSITION);
       read(Picture, CurrentCode);
       CurrentChar := chr(CurrentCode);
       HiddenString := HiddenString + CurrentChar;
    end;
  closeFile(Picture);
  write('Text hidden in picture: ' + HiddenString);
  readln;
end.
Programming - a skill for life!

Changing colours, copying images and hiding data