2017-12-15

Navigation

Skip Navigation Links

Hash algorithms

Asymmetric Algorithms

Symmetric Cipher Algorithms

Encoding Algorithms

Compression Algorithms

Pseudo Random Number Algorithms

Steganography

Library Wrappers

String Comparison

Others

Syntax highlighting by Prism
PBCrypto.com Mirror

Hide text in BMP color table

Algorithm creator(s)

n/a


PB author(s)

Peter Lameijn


Description

This method uses the color table to store the hidden message. This severely limits the amount of data that can be stored, but has many other advantages, including leaving the actual image data untouched.


Note

This sample leaves the hidden message as visible plaintext


Source

https://forum.powerbasic.com/forum/user-to-user-discussions/source-code/24148-steganography-hide-a-message-inside-a-bitmap-image?t=23511


See also

n/a


Source Code

Download source code file steg-bmptable.bas (Right-click -> "Save as ...")

Data modification sample:
 Before: 00000080000080000000808000800000008000800080800000C0C0C000C0DCC000F0CAA60004040400080808000C0C0C0011111100161616001C1C1C00
 After : 450000806D0080006200808065800000648000806480800065C0C0C064C0DCC020F0CAA67404040465080808730C0C0C741111112E1616162E1C1C1C2E
         ^^      ^^      ^^      ^^      ^^      ^^      ^^      ^^      ^^      ^^      ^^      ^^      ^^      ^^      ^^      ^^
   
'==============================================================================
#Compile Exe
#Include "win32api.inc" 

'------------------------------------------------------------------------------
Function WriteBmpText(BmpFile As String, sPlainText As String) As Long
  Local BMFH As BITMAPFILEHEADER, hFile As Dword, dStr As String, CtLen As Dword, Cnt As Long
  hFile = FreeFile
  Open BmpFile For Binary As #hFile
    Get$ #hFile, 14, dStr
    Poke$ VarPtr(BMFH), dStr
    Get$ #hFile, 40, dStr
    CtLen = (BMFH.bfOffBits - 14 - 40) \ 4
    Print "Max. number of characters to embed is" + Str$(CtLen)
    If Len(sPlainText) <= CtLen Then
      For Cnt = 1 To Len(sPlainText)
        Get$ #hFile, 3, dStr
        Put$ #hFile, Mid$(sPlainText, Cnt, 1)
      Next
      Function = 1
    End If
  Close #hFile
End Function 

'------------------------------------------------------------------------------
Function ReadBmpText (BmpFile As String) As String
  Local BMFH As BITMAPFILEHEADER, hFile As Dword, dStr As String, Cnt As Long, Text As String
  hFile = FreeFile
  Open BmpFile For Binary As hFile
  Get$ #hFile, 14, dStr
  Poke$ VarPtr(BMFH), dStr
  Get$ #hFile, 40, dStr
  For Cnt = 1 To ((BMFH.bfOffBits - 54) \ 4)
    Get$ #hFile, 4, dStr
    If Mid$(dStr,4,1) = Chr$(0) Then Exit For
    Text = Text + Mid$(dStr,4,1)
  Next
  Close #hFile
  Function = Text
End Function 

'------------------------------------------------------------------------------
Function PbMain() As Long
  Local dStr As String
If Dir$("c:\temp\textbmp.bmp") <> "" Then Kill "c:\temp\textbmp.bmp"
FileCopy "c:\winnt\winnt256.bmp", "c:\temp\textbmp.bmp" 
WriteBmpText "c:\temp\textbmp.bmp", "Embedded test..."
dStr =  ReadBmpText  ("c:\temp\textbmp.bmp")
Print "Retrieved text: " ; dStr
WaitKey$
End Function

Mirror provided by Knuth Konrad