Posts: 1,114
Threads: 699
Joined: Sep 2016
If MsgBox("You are about to encrypt and embed this message :[[
" + TextBox1.Text + " ]] , Shall We Proceed?", MsgBoxStyle.OkCancel,
"Stealth") = MsgBoxResult.Cancel Then Exit Sub
Label2.Text = ""
If RadioButton1.Checked = False And RadioButton2.Checked = False Then
MsgBox("Please select an extention")
Exit Sub
End If
Dim text As String
text = TextBox1.Text.ToString + " "
Dim passw As String = "" input("Enter Password To Protect Your Text", passw)
If passw = "" Then 'err handler for ugly passwords
MsgBox("Error ! You Didn,t Choose Any Password To Protect The Message.")
Exit Sub
ElseIf passw.Length < 4 Then
MsgBox("Error ! Password Is Too Short.")
Exit Sub
End If
Dim amount As Double = text.Length
process_pass_with_tx(passw, text) ' this will encrypt the test by the
' password this is done by generating a string from the password and this
' string is tall enough to perform bit stream xor operation on all chares
' included in the message text that we want to send. we secured the text,
' now we will try hide the encrypted text in the image.
TextBox1.Text = text
If RadioButton1.Checked = True Then GoTo mode2 ''started deferences
between tow modes here
If Me.OpenFileDialog1.ShowDialog = DialogResult.Cancel Then
Exit Sub
Else 'err handler to prevent wrong extensions
Dim infoReader As System.IO.FileInfo
infoReader = My.Computer.FileSystem.GetFileInfo(
Me.OpenFileDialog1.FileName)
If infoReader.Extension.Substring(1, 3).ToLower <> (
RadioButton2.Text.ToLower) Then
MsgBox("Error : Encryption mode requires different extension ")
Exit Sub
End If
LoadNewPict(Me.OpenFileDialog1.FileName) 'display the selected image preview
If PictureBox1.Image.Size.Width < 64 Or PictureBox1.Image.Size.Height <
64 Then
' prevent user from using unproperiate images
MsgBox("Error! Tiny Images Cann,t Be Used In Steganography.")
Exit Sub
End If
Dim w1 As Integer = PictureBox1.Image.Size.Width - 1
Dim w2 As Integer = PictureBox1.Image.Size.Height - 1
Dim possible_size As Double = ((w1 - 7) * (w2 - 7)) / 8 ' 8 bits make one
' char, and avoid edges
If possible_size < amount Then ' determine if the image is not big enough
' for text
MsgBox("This image is not big enough to carry your message",
MsgBoxStyle.Critical)
Exit Sub
End If
End If ' file dialog if
' load accurding to extention
Dim dib, val, reslt As Integer
dib = FreeImage.FreeImage_Load(FreeImage.FREE_IMAGE_FORMAT.FIF_TIFF,
OpenFileDialog1.FileName, 0)
On Error GoTo rongex1
Dim ba As bits_array
ba.Initialize()
Dim sz As Long
Dim sz1, sz2, sz3, sz4 As Byte
Dim t As Double sz = text.Length ' number of chars to encrypt
sz1 = Decimal.Remainder(sz, 100) ' take the lowest 2 digits of it
t = sz / 100 'take the left numbers (all except lowest 2 digits)
sz = Decimal.Truncate(t) ' set size_variable to hold left numbers (all except
' lowest 2 digits)
sz2 = Decimal.Remainder(sz, 100) ' repeat
t = sz / 100
sz = Decimal.Truncate(t)
sz3 = Decimal.Remainder(sz, 100) ' ' repeat
t = sz / 100
sz = Decimal.Truncate(t)
sz4 = Decimal.Remainder(sz, 100) ' will take final 2 digits, now you can
' see: the maximum size of text is ( 99 99 99 99 )
' now we will convert sz1 to bits array and stor it in the first line of the
' picture after it we will do the sz2 and then sz3 and then sz4..
' the coming 4 for loops are used for that
Dim i, j, m
i = 0
j = 1
ba.Initialize()
byte_to_bits(sz1, ba)
For m = 0 To 7 '''''''''''''''''' 1
i = i + 1
FreeImage.FreeImage_GetPixelColor(dib, i, j, val)
' set the lowest bit according to my bit
If odd(val) = True Then
If ba.bits(m) = False Then 'bit is zero
FreeImage.FreeImage_SetPixelColor(dib, i, j, (val + 1))
End If
End If
If odd(val) = False Then
If ba.bits(m) = True Then 'bit is one
FreeImage.FreeImage_SetPixelColor(dib, i, j, (val + 1))
End If
End If
Next m
ba.Initialize()
byte_to_bits(sz2, ba)
For m = 0 To 7 '''''''''''''''''''''' 2
i = i + 1
FreeImage.FreeImage_GetPixelColor(dib, i, j, val)
If odd(val) = True Then
If ba.bits(m) = False Then 'bit is zero
FreeImage.FreeImage_SetPixelColor(dib, i, j, val + 1)
End If
End If
If odd(val) = False Then
If ba.bits(m) = True Then 'bit is one
FreeImage.FreeImage_SetPixelColor(dib, i, j, val + 1)
End If
End If
Next m
ba.Initialize()
byte_to_bits(sz3, ba)
For m = 0 To 7 '''''''''''''''''''''''''''' 3
i = i + 1
FreeImage.FreeImage_GetPixelColor(dib, i, j, val)
If odd(val) = True Then
If ba.bits(m) = False Then 'bit is zero
FreeImage.FreeImage_SetPixelColor(dib, i, j, val + 1)
End If
End If
If odd(val) = False Then
If ba.bits(m) = True Then 'bit is one
FreeImage.FreeImage_SetPixelColor(dib, i, j, val + 1)
End If
End If
Next m
ba.Initialize()
byte_to_bits(sz4, ba)
For m = 0 To 7 ''''''''''''''''''''''''''''' 4
i = i + 1
FreeImage.FreeImage_GetPixelColor(dib, i, j, val)
If odd(val) = True Then
If ba.bits(m) = False Then 'bit is zero
FreeImage.FreeImage_SetPixelColor(dib, i, j, val + 1)
End If
End If
If odd(val) = False Then
If ba.bits(m) = True Then 'bit is one
FreeImage.FreeImage_SetPixelColor(dib, i, j, val + 1)
End If
End If
Next m '''' we have just stored the size of the text
Dim n As Byte
Dim count As Long
count = 0 'i already set size ===>>> first line for size
' Now i will scan the picture from the second line
For j = 2 To PictureBox1.Image.Size.Height Step 1
i = 1
Do While (i + 7) < PictureBox1.Image.Size.Width ' Step 8 ' may use
' freeimage_getdotspermeterx
n = Asc(CChar(text.Substring(count, 1))) ' this give ascii code for
' the every text letter, to reverse it use chr() function
count = count + 1
If count = text.Length Then GoTo out
ba.Initialize()
byte_to_bits(n, ba) '''''''''''
For m = 0 To 7
FreeImage.FreeImage_GetPixelColor(dib, i, j, val)
' change it according to my bit
If odd(val) = True Then
If ba.bits(m) = False Then 'bit is zero
FreeImage.FreeImage_SetPixelColor(dib, i, j, val + 1)
End If
End If
If odd(val) = False Then
If ba.bits(m) = True Then 'bit is one
FreeImage.FreeImage_SetPixelColor(dib, i, j, val + 1)
End If
End If
i = i + 1
Next m
i = i + 8
Loop
Next j
out:
Dim fn As String
Dim con As Integer = 0
fn = OpenFileDialog1.FileName + "_stealth.tif"
up1:
If File.Exists(fn) = False Then
FreeImage.FreeImage_Save(FreeImage.FREE_IMAGE_FORMAT.FIF_TIFF,
dib, fn, &H800S)
Else
con = con + 1
MsgBox("FILE: " + fn + " ALREADY EXISTS ,WE WILL CHANGE THE NAME TO " +
OpenFileDialog1.FileName + con.ToString + "_stealth.tif")
fn = OpenFileDialog1.FileName + con.ToString + "_stealth.tif"
GoTo up1
End If
Label2.Text = fn
Exit Sub
mode2: '
' in mode2 we will treat the file with the deferent extension in the same
way, just change the lib calls according to the extension
' to decrypt the message we will reverse what we have done .