Page 1 of 2

Cryprtography (Text - Picture)

Posted: Thu Jan 20, 2011 1:49 pm
by Tilen
Hello to my tutorial on how to make program that will do what title says. ;)

Let's begin!


Source code may be downloaded here:
viewtopic.php?f=71&t=4516&#p32971

ADD:

2 Buttons:
- Button1 //Load image
- Button2 //Preform action
2 Radiobuttons:
-RadioButton1 //Encrypt Text
-RadioButton2 //Decrypt Text
3 Textboxes:
-TextBox1 //Text that's going to "go" in picture
-TextBox2 //This one will show picture's location
-TextBox3 //Text etrieved from picture
1 PictureBox
-PictureBox1 //Preview of picture
1 Openfiledialog
-openpic //Opens picture
1 Savefiledialog
-buildpic //Saves picture
CODE(s):

Bellow "Public class form1":
Code: Select all
Dim PicBuffer As System.IO.FileInfo

Button1:
Code: Select all
openPic.Title = "Open Picture Files"
        openPic.ShowDialog()
Button2:
Code: Select all
Dim Ready As Boolean = True
        Dim PicFileStream As System.IO.FileStream
        Try
            PicFileStream = PicBuffer.OpenRead
        Catch ex As Exception
            Ready = False
            MsgBox("Please load a picture before clicking this button", MsgBoxStyle.Critical, "Error")
        End Try
        If Ready = True Then
            Dim PicBytes As Long = PicFileStream.Length
            Dim PicExt As String = PicBuffer.Extension
            Dim PicByteArray(PicBytes) As Byte
            PicFileStream.Read(PicByteArray, 0, PicBytes)
            Dim SentinelString() As Byte = {73, 116, 83, 116, 97, 114, 116, 115, 72, 101, 114, 101}
            If RadioButton1.Checked = True Then
                Dim PlainText As String = TextBox1.Text
                Dim PlainTextByteArray(PlainText.Length) As Byte
                For i As Integer = 0 To (PlainText.Length - 1)
                    PlainTextByteArray(i) = CByte(AscW(PlainText.Chars(i)))
                    Application.DoEvents()
                Next
                Dim PicAndText(PicBytes + PlainText.Length + SentinelString.Length) As Byte
                For t As Long = 0 To (PicBytes - 1)
                    PicAndText(t) = PicByteArray(t)
                Next
                Dim count As Integer = 0
                For r As Long = PicBytes To (PicBytes + (SentinelString.Length) - 1)
                    PicAndText(r) = SentinelString(count)
                    count += 1
                Next
                count = 0
                For q As Long = (PicBytes + SentinelString.Length) To (PicBytes + SentinelString.Length + PlainText.Length - 1)
                    PicAndText(q) = PlainTextByteArray(count)
                    count += 1
                Next
                buildPic.ShowDialog()
                Dim NewFileName As String = buildPic.FileName
                My.Computer.FileSystem.WriteAllBytes(NewFileName, PicAndText, False)

            ElseIf RadioButton2.Checked Then
                TextBox3.Clear()
                Dim OutterSearch, InnerSearch, StopSearch As Boolean
                OutterSearch = True
                InnerSearch = True
                StopSearch = False
                Dim count As Long = 0
                Dim leftCounter As Long
                Dim rightCounter As Integer
                leftCounter = 0
                rightCounter = 0
                Do While (count < (PicBytes - SentinelString.Length) And StopSearch = False)
                    If (PicByteArray(count) = SentinelString(0)) Then
                        leftCounter = count + 1
                        rightCounter = 1
                        InnerSearch = True
                        Do While (InnerSearch = True) And (rightCounter < SentinelString.Length) _
                        And (leftCounter < PicByteArray.Length)
                            If (PicByteArray(leftCounter) = SentinelString(rightCounter)) Then
                                rightCounter += 1
                                leftCounter += 1
                                If (rightCounter = (SentinelString.Length - 1)) Then
                                    StopSearch = True
                                End If
                            Else
                                InnerSearch = False
                                count += 1
                            End If
                        Loop
                    Else
                        count += 1
                    End If
                Loop
                If StopSearch = True Then
                    'leftCounter contains the starting string that is being retrieved
                    Do While (leftCounter < PicBytes)
                        'Bytes need to be converted to an integer 
                        'then to an unicode character which will be the plaintext
                        TextBox3.AppendText(ChrW(CInt(PicByteArray(leftCounter))))
                        leftCounter += 1
                    Loop
                Else
                    TextBox3.Text = "The Picture does not contain any text"
                End If

            End If
        End If

RadioButton1:
Code: Select all
TextBox1.Enabled = True
RadioButton2:
Code: Select all
TextBox1.Enabled = False

openPic_fileOK:
Code: Select all
 PictureBox1.Image = Image.FromFile(openPic.FileName)
        PicBuffer = New System.IO.FileInfo(openPic.FileName)
        ResizeFileName(openPic.FileName, PicBuffer.Name)

Sub ResizeFileName(ByVal LongFileName As String, ByVal ShortFileName As String):
Code: Select all
 If LongFileName.Length > 71 Then
            Dim LongFileNameSize As Integer = LongFileName.Length
            Dim ShortFileNameSize As Integer = ShortFileName.Length
            Dim Cut As Integer = 71 - (5 + ShortFileNameSize)
            Dim i As Integer
            TextBox2.Clear()
            For i = 0 To (Cut) - 1
                TextBox2.AppendText(LongFileName.Chars(i))
            Next
            For i = 0 To 4
                TextBox2.AppendText(".")
            Next
            For i = 0 To (ShortFileNameSize - 1)
                TextBox2.AppendText(ShortFileName(i))
            Next
        Else
            TextBox2.Text = LongFileName
        End If



Result:
1:
Image
Image



Source code is comming soon, link will be Here!

Re: Cryprtography (Text - Picture)

Posted: Thu Jan 20, 2011 2:46 pm
by DarkyKnife
That is really amazing work, good job.

Re: Cryprtography (Text - Picture)

Posted: Thu Jan 20, 2011 3:12 pm
by Codex
Umm sorry but what exactly does this program do?

Re: Cryprtography (Text - Picture)

Posted: Thu Jan 20, 2011 3:34 pm
by Tilen
codex, its hard to explain.

youll need to figure out by yourself


it hides text to image (you cant see it)

also it can show those messages

great way to protect pictures

Re: Cryprtography (Text - Picture)

Posted: Thu Jan 20, 2011 3:59 pm
by NecroPhis
oh nice project :O

Re: Cryprtography (Text - Picture)

Posted: Thu Jan 20, 2011 4:13 pm
by Tilen
thanks, necro.

Re: Cryprtography (Text - Picture)

Posted: Thu Jan 20, 2011 4:33 pm
by NoWayIn
To be honest this is a copy and paste kind of thingy o.o it doesnt really teach anyone anything unless they really want to learn by examining the codes

Re: Cryprtography (Text - Picture)

Posted: Thu Jan 20, 2011 5:09 pm
by Tilen
agree with you. thats why i didnt put whole source.

Re: Cryprtography (Text - Picture)

Posted: Sat Jan 22, 2011 2:08 pm
by code it

Re: Cryprtography (Text - Picture)

Posted: Sat Jan 22, 2011 2:35 pm
by Tilen
code it wrote:
The program is in the site xD

http://m-t-h.weebly.com/uploads/4/9/2/2 ... graphy.exe
http://www.m-t-h.co.cc/
ohya.

and thanks for visiting my site dude!!! cooll; wahooo;