VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Hides string information in WAV or BMP files using steganography. Uses 2 bits out of every 16 to hi

by Kevin O'Classen ()
Category: Encryption
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Wed 23rd June 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Hides string information in WAV or BMP files using steganography. Uses 2 bits out of every 16 to hide information "in plain sight".

API Declarations



' Steganography is the process of "hiding information in plain sight".
' These functions will hide text information in either WAV or BMP files,
' while leaving them still able to be played or displayed normally, with little
' to no loss of quality. Works by altering the 2 least significant bits of each
' sample (2 bits out of 16). A one-byte flag (Chr(255)) is used to signify
' the end of the hidden data. The data that is hidden is not encrypted in any
' way... This would be done before calling these routines.

'--- There is little to no error checking, and no provisions to avoid
' overwriting a file that has been modified.

' The Embed function returns an integer value showing the results of trying
' to embed the data. The Pull function returns a string containing any data
' retreived from the file. In both cases, the filename supplied must be a full
' file name, rather than a relative path.

' I wrote this code using VB6, but the process is so basic I expect
' it should work with all versions. No API or process calls, no components.

' If you find this code useful, have questions, or if you've written a better
' routine, don't hesitate to drop me a line at <[email protected]>


Rate Hides string information in WAV or BMP files using steganography. Uses 2 bits out of every 16 to hi



'Returns
    '    0  --- executed successfully
    '    1  --- file not found
    '    2  --- Data too long for file -- excess truncated

Dim Alpha As Integer, Beta As Byte, Gamma As Long
Dim Byte2Hide As Byte, Bits2Hide As Byte, Working As Byte, Limit As Long

    Embed = 0
    embedME = embedME & Chr(255)
    Gamma = 255

    If Dir(filename) = "" Then Embed = 1: Exit Function
    Limit = FileLen(filename)

Open filename For Binary As #1

For Alpha = 1 To Len(embedME)
    Byte2Hide = Asc(Mid(embedME, Alpha, 1))
    
    For Beta = 0 To 7 Step 2
       Bits2Hide = 0
       If (Byte2Hide And (2 ^ Beta)) Then Bits2Hide = Bits2Hide Or 1
       If (Byte2Hide And (2 ^ (Beta + 1))) Then Bits2Hide = Bits2Hide Or 2
        Get #1, Gamma, Working
        Working = Working And 252
        Working = Working Or Bits2Hide
        Put #1, Gamma, Working
        Gamma = Gamma + 2
        
        If Gamma >= Limit Then
            Embed = 2
            Close 1
            Exit Function
        End If
        
    Next
    Next
    Close 1
    

End Function

' -----------------------------------------------------
Public Function Pull(filename As String) As String
    ' returns a string containing the data buried in the file
    
    Dim Mask As Byte, Beta As Byte, Gamma As Long, Fetch As Byte, Hold As Byte
    
    
    Pull = ""
    Gamma = 255
    Open filename For Binary As #1
    Do
    DoEvents
     Hold = 0
        For Beta = 0 To 7 Step 2
        Mask = 0
        Get #1, Gamma, Fetch
            If (Fetch And 1) Then Mask = Mask Or 2 ^ Beta
            If (Fetch And 2) Then Mask = Mask Or 2 ^ (Beta + 1)
                                                                    
        Hold = Hold Or Mask
        Gamma = Gamma + 2
        Next
        
        If Hold = 255 Then Close 1: Exit Function
        Pull = Pull & Chr(Hold)
    Loop
    

End Function

Download this snippet    Add to My Saved Code

Hides string information in WAV or BMP files using steganography. Uses 2 bits out of every 16 to hi Comments

No comments have been posted about Hides string information in WAV or BMP files using steganography. Uses 2 bits out of every 16 to hi. Why not be the first to post a comment about Hides string information in WAV or BMP files using steganography. Uses 2 bits out of every 16 to hi.

Post your comment

Subject:
Message:
0/1000 characters