• Tidak ada hasil yang ditemukan

LISTING PROGRAM Kode Program Form Main (Menu Utama) :

N/A
N/A
Protected

Academic year: 2019

Membagikan "LISTING PROGRAM Kode Program Form Main (Menu Utama) :"

Copied!
25
0
0

Teks penuh

(1)

LISTING PROGRAM

Kode Program Form Main (Menu Utama) :

Private Sub lbAdd_Click()

frmAdd.Show vbModeless, Me End Sub

Private Sub lbExtract_Click()

frmRead.Show vbModeless, Me End Sub

Private Sub Label1_Click()

frmMSEStego.Show End Sub

Private Sub Label4_Click()

End End Sub

Kode Program Form Add (Insertion) :

Option Explicit Dim vSteps

Dim currentStep& Const MAX_STEPS = 3 Dim strImageFile$ Dim m_Millimeter&

Dim WithEvents clsStega As ClsStegano Dim bolCover As Boolean

Dim bolEmbed As Boolean Dim NewColor As Long

Private Sub clsStega_SomeError(strDescription As String) MsgBox "Some error: " & strDescription

End Sub

Private Sub clsStega_StatusChanged(prcDone As Long, strStatus As String)

frmLoad.ProgBar.Value = prcDone frmLoad.lbStatus = strStatus End Sub

Private Sub cmdAddFile_Click()

Dim thedata$, theKey$, sTitle$ Dim Itlvw As ListItem

Dim lebar As Integer Dim Tinggi As Integer

files.Filter = "Jenis Citra|*.bmp" files.FileName = ""

files.ShowOpen

bolEmbed = True

(2)

picEmbed.Picture = LoadPicture(thedata) lebar = picEmbed.ScaleWidth

Tinggi = picEmbed.ScaleHeight Me.Caption = lebar & " " & Tinggi If lebar >= 32 And Tinggi >= 32 Then MsgBox "Citra embed terlalu besar" picEmbed.Picture = Nothing

currentStep = currentStep - 1 cmdRemove.Enabled = True cmdRemove_Click

Shape6.Visible = True cmdAddFile.Enabled = True

Else

lblNmFile1.Caption = files.FileTitle

sTitle = VBA.Left$(files.FileTitle, Len(files.FileTitle) - 4) If thedata <> "" Then

theKey = "f0" & lvwFilesAdded.ListItems.Count + 1 If clsStega.AddFile(thedata, sTitle, theKey) Then Set Itlvw = lvwFilesAdded.ListItems.Add(, theKey, VBA.Right$(thedata, 3))

Itlvw.SubItems(1) = sTitle

Itlvw.SubItems(2) = FileLen(thedata)

lbRema = "Sisa Byte: " & clsStega.BytesTotal - clsStega.BytesAdded

cmdNext.Enabled = True cmdBack.Enabled = False cmdTarget.Enabled = False cmdAddFile.Enabled = False cmdRemove.Enabled = True Label5.Enabled = False

End If End If End If End Sub

Private Sub cmdBack_Click()

cmdNext.Enabled = True cmdFinish.Enabled = False If currentStep >= 0 Then

frStep(currentStep).Visible = False currentStep = currentStep - 1

lbStep = vSteps(currentStep)

If currentStep < 0 Then currentStep = 0

frStep(currentStep).Visible = True

If currentStep = 0 Then cmdBack.Enabled = False End If

End Sub

Private Sub cmdFinish_Click()

Set clsStega = Nothing Unload Me

End Sub

Private Sub cmdNext_Click()

(3)

cmdNext.Enabled = False cmdBack.Enabled = True

currentStep = currentStep + 1

If currentStep >= MAX_STEPS Then cmdBack.Enabled = False cmdNext.Enabled = False cmdFinish.Enabled = True End If

If currentStep = 1 Then

cmdAddFile.Enabled = True Label5.Enabled = False cmdBack.Enabled = True Else

cmdAddFile.Enabled = False End If

If currentStep = 2 Then cmdBack.Enabled = False frmLoad.Show vbModeless, Me clsStega.EncodeIt

files.FileName = ""

files.Filter = "Simpan Stego Image|*.bmp" files.ShowSave

If files.FileName <> "" Then

lblNmFile2.Caption = files.FileTitle clsStega.OutputImageFile = files.FileName clsStega.Save2Image

picStego.Picture = LoadPicture(files.FileName)

SavePicture picStego.Image, files.FileName Else

MsgBox "Batal simpan!" End If

Unload frmLoad End If

End Sub

Private Sub cmdRemove_Click()

Dim ItSel As ListItem

Set ItSel = lvwFilesAdded.SelectedItem If Not ItSel Is Nothing Then

clsStega.RemoveFile ItSel.Key

lbRema = "Sisa Bytes: " & clsStega.BytesTotal - clsStega.BytesAdded

lvwFilesAdded.ListItems.Remove ItSel.Index End If

If lvwFilesAdded.ListItems.Count = 0 Then cmdNext.Enabled = False cmdAddFile.Enabled = True

cmdRemove.Enabled = False End Sub

Private Sub cmdTarget_Click()

Dim ToW&, ToH&, InW&, InH&, mPad& Dim lebar As Integer

Dim Tinggi As Integer

mPad = 2

(4)

files.ShowOpen

bolCover = True

strImageFile = files.FileName

TheImage.Picture = LoadPicture(strImageFile) lebar = TheImage.Width

Tinggi = TheImage.Height

Me.Caption = lebar & " " & Tinggi If lebar <= 350 And Tinggi <= 250 Then

lblNmFile.Caption = files.FileTitle

If strImageFile <> "" And VBA.Right$(strImageFile, 4) = ".bmp" Then

TheImage.Picture = LoadPicture(strImageFile)

clsStega.ImageFile = strImageFile ToW = Me.ScaleWidth - mPad - mPad ToH = Me.ScaleHeight - mPad - mPad

InW = TheImage.Picture.Width / m_Millimeter InH = TheImage.Picture.Height / m_Millimeter VS.Max = InH - HS.Top + mPad

HS.Max = InW - VS.Left + mPad VS.LargeChange = ToH - HS.Height HS.LargeChange = ToW - VS.Width

lbRema = "Sisa Bytes: " & clsStega.BytesTotal

cmdNext.Enabled = True Label5.Enabled = TruE Else

MsgBox "Error citra", vbCritical, "File rusak" End If

Else

MsgBox "Citra Cover terlalu besar" TheImage.Picture = Nothing

TheImage.Cls End If

End Sub

Private Sub Form_Activate()

cmdFinish.Enabled = True cmdAddFile.Enabled = False cmdRemove.Enabled = False Label5.Enabled = True End Sub

Private Sub Form_Load()

Set clsStega = New ClsStegano currentStep = 0

m_Millimeter = ScaleX(100, vbPixels, vbMillimeters)

vSteps = Array("Langkah 1: Pilih Cover Image:", "Langkah 2: Pilih Embed Image:", "Langkah 3: Penyisipan Embed Image:", "Selesai")

End Sub

Private Sub Form_Unload(Cancel As Integer)

(5)

Private Sub HS_Change()

TheImage.Move -HS.Value End Sub

Private Sub HS_Scroll()

TheImage.Move -HS.Value End Sub

Private Sub Label5_Click()

picStego.Picture = Nothing TheImage.Picture = Nothing lblNmFile = ""

lblNmFile1 = "" lblNmFile2 = "" lbRema = ""

lvwFilesAdded.ListItems.Clear Label5.Enabled = False

cmdFinish.Enabled = True End Sub

Private Sub VS_Change()

TheImage.Move TheImage.Left, -VS.Value End Sub

Private Sub VS_Scroll()

TheImage.Move TheImage.Left, -VS.Value End Sub

Private Sub GET_COLORS(COLOR As Long, ByRef R As Single, ByRef G As Single, ByRef B As Single)

R = COLOR And RGB(255, 0, 0)

G = Int((COLOR And RGB(0, 255, 0)) / 256)

B = Int(Int((COLOR And RGB(0, 0, 255)) / 256) / 256)

NewColor = COLOR If R > 256 Then R = 256

ElseIf R < 0 Then R = 0

End If

If G > 256 Then G = 256

ElseIf G < 0 Then G = 0

End If

If B > 256 Then B = 256

ElseIf B < 0 Then B = 0

End If

End Sub

Kode Program Form Read (Menu Ekstraksi) :

(6)

Dim m_Millimeter& Dim vSteps

Const MAX_STEPS = 2 Dim currentStep&

Dim WithEvents clsStegaRead As ClsStegano

Private Sub clsStegaRead_SomeError(strDescription As String) MsgBox strDescription

End Sub

Private Sub clsStegaRead_StatusChanged(prcDone As Long, strStatus As String)

frmLoad.ProgBar.Value = prcDone frmLoad.lbStatus = strStatus End Sub

Private Sub cmdExtract_Click()

Dim ItSel As ListItem Dim OutFile&, tmpFile& Dim dataOut() As Byte On Error GoTo errExtrac

Set ItSel = lvwFilesAdded.SelectedItem If Not ItSel Is Nothing Then

Files.FileName = ""

Files.Filter = "File|*." & ItSel.Text Files.ShowSave

If Files.FileName <> "" Then Dim ItFile As ClsFile tmpFile = FreeFile

Set ItFile = clsStegaRead.GetFile(ItSel.Key) Open ItFile.FileName For Binary As tmpFile dataOut() = InputB(LOF(tmpFile), tmpFile) Close tmpFile

OutFile = FreeFile

Open Files.FileName For Binary As OutFile Put OutFile, , dataOut()

Close OutFile

lblNmFile1.Caption = Files.FileTitle

picEmbed.Picture = LoadPicture(Files.FileName) MsgBox "Ekstraksi sukses!"

End If

End If

cmdTarget.Enabled = False cmdExtract.Enabled = False Label5.Enabled = True cmdFinish.Enabled = True Exit Sub

errExtrac:

MsgBox Err.Description End Sub

Private Sub cmdFinish_Click()

(7)

Private Sub cmdNext_Click()

cmdNext.Enabled = False

currentStep = currentStep + 1 lbStep = vSteps(currentStep)

frStep(currentStep).Visible = True

If currentStep >= MAX_STEPS Then cmdNext.Enabled = False cmdFinish.Enabled = True End If

If currentStep = 1 Then

frmLoad.Show vbModeless, Me

If Not clsStegaRead.DecodeIt Then

MsgBox "Embed Image tidak ada ...." currentStep = MAX_STEPS - 1

Else

Dim ItTmp As ClsFile, Itlvw As ListItem Dim I&

I = 1

For Each ItTmp In clsStegaRead

Set Itlvw = lvwFilesAdded.ListItems.Add(, ItTmp.KeyFile, ItTmp.TypeFile)

Itlvw.SubItems(1) = ItTmp.FileTitle Itlvw.SubItems(2) = ItTmp.LenBytes I = I + 1

Next

lbRema = "Bytes attached in Image: " & clsStegaRead.BytesAdded

End If

cmdNext_Click

Unload frmLoad End If

cmdExtract.Enabled = True Label5.Enabled = False cmdTarget.Enabled = False If currentStep = 2 Then End IF

End Sub

Private Sub cmdTarget_Click()

Dim ToW&, ToH&, InW&, InH&, mPad& mPad = 2

Files.Filter = "Image File|*.bmp" Files.ShowOpen

strImageFile = Files.FileName

lblNmFile.Caption = Files.FileTitle

If strImageFile <> "" And VBA.Right$(strImageFile, 4) = ".bmp" Then

TheImage.Picture = LoadPicture(strImageFile)

clsStegaRead.ImageFile = strImageFile

ToW = Me.ScaleWidth - mPad - mPad ToH = Me.ScaleHeight - mPad - mPad

(8)

VS.Max = InH - HS.Top + mPad HS.Max = InW - VS.Left + mPad VS.LargeChange = ToH - HS.Height HS.LargeChange = ToW - VS.Width

cmdNext.Enabled = True Else

MsgBox "Error file", vbCritical, "Citra rusak" End If

End Sub

Private Sub Form_Load()

cmdExtract.Enabled = False currentStep = 0

Set clsStegaRead = New ClsStegano

m_Millimeter = ScaleX(100, vbPixels, vbMillimeters)

vSteps = Array("Langkah 1: Pilih Stego Image:", "Langkah 2: Ekstraksi embed image:", "Langkah 3: Pilih citra untuk di

ekstraksi:", "Selesai")

End Sub

Private Sub Form_Unload(Cancel As Integer)

Dim It As ListItem

For Each It In lvwFilesAdded.ListItems Kill clsStegaRead(It.Key).FileName Next

Set clsStegaRead = Nothing End Sub

Private Sub HS_Change()

TheImage.Move -HS.Value End Sub

Private Sub HS_Scroll()

TheImage.Move -HS.Value End Sub

Private Sub Label5_Click()

TheImage.Picture = Nothing lblNmFile = ""

lvwFilesAdded.ListItems.Clear picEmbed.Picture = Nothing lblNmFile1 = ""

Label5.Enabled = False End Sub

Private Sub VS_Change()

TheImage.Move TheImage.Left, -VS.Value End Sub

Private Sub VS_Scroll()

TheImage.Move TheImage.Left, -VS.Value End Sub

Kode Program Form MSEStego (Hitung MSE) :

Option Explicit

(9)

Private Declare Function SetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long Dim wt(400, 400) As Integer

Dim h(3, 3) As Single Dim R1 As Single Dim G1 As Single Dim B1 As Single Dim NewColor As Long Dim NewColor1 As Long Dim R2 As Single Dim G2 As Single Dim B2 As Single Dim Gray1 As Single Dim Gray2 As Single Dim X1, Y1 As Single Dim X2, Y2 As Single Dim X, Y As Integer Dim MSE As Single Dim Dimensi1 As Single Dim Dimensi2 As Single Dim TNilPixel As Single Dim Selisih As Single Dim TSelisih As Single

Private Declare Function SetPixelV Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Byte Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long) As Long

Private Sub GET_COLORS(COLOR As Long, ByRef R As Single, ByRef G As Single, ByRef B As Single)

NewColor = 0

R = COLOR And RGB(255, 0, 0)

G = Int((COLOR And RGB(0, 255, 0)) / 256)

B = Int(Int((COLOR And RGB(0, 0, 255)) / 256) / 256)

NewColor = COLOR If R > 256 Then R = 256

ElseIf R < 0 Then R = 0

End If

If G > 256 Then G = 256

ElseIf G < 0 Then G = 0

End If

If B > 256 Then B = 256

ElseIf B < 0 Then B = 0

End If End Sub

Sub Proses()

For X1 = 0 To 175 Step 10 DoEvents

(10)

GET_COLORS PicCover.Point(X, Y), R1, G1, B1 If R1 > 255 Then R1 = 255

If R1 < 0 Then R1 = 0 If B1 > 255 Then B1 = 255 If B1 < 0 Then B1 = 0 If G1 > 255 Then G1 = 255 If G1 < 0 Then G1 = 0

Gray1 = (R1 + G1 + B1) / 3 If Gray1 < 0 Then Gray1 = 0 If Gray1 > 255 Then Gray1 = 255

For X2 = 0 To 175 Step 10 DoEvents

For Y2 = 0 To 125 Step 10 DoEvents

GET_COLORS picStego.Point(X, Y), R2, G2, B2 If R2 > 255 Then R2 = 255

If R2 < 0 Then R2 = 0 If B2 > 255 Then B2 = 255 If B2 < 0 Then B2 = 0 If G2 > 255 Then G2 = 255 If G2 < 0 Then G2 = 0

Gray2 = (R2 + G2 + B2) / 3 If Gray2 < 0 Then Gray2 = 0 If Gray2 > 255 Then Gray2 = 255

Selisih = Abs(Gray1 - Gray2)

TSelisih = TSelisih + (Selisih ^ 2) ' Tselisih : total selisih

lblMSE.Caption = Format(TSelisih, "###.##") Gray1 = 0

Gray2 = 0 Next Y2

Next X2 Next Y1

Next X1

MSE = (1 / Dimensi1) * Tselisih

lblMSE.Caption = Format(MSE, "###.##") End Sub

Private Sub cmdBersih_Click()

PicCover.Picture = Nothing picStego.Picture = Nothing lblNmFile = ""

lblNmFile1 = "" lblDimensi = "" lblMSE = "" MSE = 0 R1 = 0 G1 = 0 B1 = 0

NewColor = 0 NewColor1 = 0 R2 = 0

(11)

Gray1 = 0 Gray2 = 0 X1 = 0 Y1 = 0 X2 = 0 Y2 = 0 X = 0 Y = 0 MSE = 0 Dimensi1 = 0 Dimensi2 = 0 TNilPixel = 0 Selisih = 0 TSelisih = 0 End Sub

Private Sub cmdLoadCover_Click()

cd.Filter = "Image File|*.bmp" cd.ShowOpen

NmFile = cd.FileName FileTitle = cd.FileTitle

lblNmFile.Caption = FileTitle If NmFile <> "" Then

PicCover.Picture = LoadPicture(NmFile) End If

Dimensi1 = PicCover.Width * PicCover.Height lblDimensi.Caption = Dimensi1

End Sub

Private Sub cmdLoadStego_Click()

cd.Filter = "Image File|*.bmp" cd.ShowOpen

NmFile1 = cd.FileName FileTitle1 = cd.FileTitle

lblNmFile1.Caption = FileTitle1

If NmFile <> "" Then

picStego.Picture = LoadPicture(NmFile1) End If

Dimensi2 = picStego.Width * picStego.Height End Sub

Private Sub cmdProses_Click()

Call Proses End Sub

Private Sub cmdSelesai_Click()

Unload Me End Sub

Kode Program Class Modules – clsStegano:

Option Explicit

(12)

Private DeepColor&

Dim BinaryAttach() As tBits, BinaryImg() As tBits Dim bImgData() As Byte, bAttachData() As Byte Dim mImageFile$

Dim mOutputImageFile$ Dim mFilesAdded& Dim OutFile& Dim mBytesLimit& Dim mBytesAdded&

Dim colFiles As Collection Dim cTAG() As Byte

Event StatusChanged(prcDone As Long, strStatus As String) Event SomeError(strDescription As String)

Public bolCover As Boolean Public bolEmbed As Boolean

Public Function NewEnum() As IUnknown Set NewEnum = colFiles.[_NewEnum] End Function

Public Property Get ImageFile() As String ImageFile = mImageFile

End Property

Public Property Let ImageFile(ByVal vNewValue As String) mImageFile = vNewValue

mBytesLimit = FileLen(mImageFile) / 8 End Property

Public Property Get FilesAdded() As Long

FilesAdded = mFilesAdded End Property

Public Function AddFile(strFile As String, strTitle As String, Key As String) As Boolean

Dim tmpFile As ClsFile On Local Error GoTo AddErr Set tmpFile = New ClsFile

If FileExist(strFile) Then With tmpFile

.KeyFile = Key .FileName = strFile .FileTitle = strTitle

.LenBytes = FileLen(strFile)

.TypeFile = VBA.Right$(strFile, 3)

mBytesAdded = mBytesAdded + .LenBytes If mBytesAdded > mBytesLimit Then

mBytesAdded = mBytesAdded - .LenBytes

Err.Raise 9001, "Tidak dapat disisip, karena embed terlalu besar !"

End If End With

End If

colFiles.Add tmpFile, Key mFilesAdded = mFilesAdded + 1 AddFile = True

(13)

AddErr:

RaiseEvent SomeError(Err.Description & " in " & Err.Source) End Function

Public Function RemoveFile(Key As String) As Boolean On Local Error GoTo AddErr

Dim tmpFile As ClsFile

Set tmpFile = colFiles(Key)

mBytesAdded = mBytesAdded - tmpFile.LenBytes

Set tmpFile = Nothing colFiles.Remove Key RemoveFile = True

mFilesAdded = mFilesAdded - 1 Exit Function

AddErr:

RaiseEvent SomeError(Err.Description) Err.Clear

End Function

Public Function GetFile(Key As String) As ClsFile On Local Error GoTo GetErr

Set GetFile = colFiles(Key) Exit Function

GetErr:

RaiseEvent SomeError(Err.Description) Err.Clear

End Function

Private Sub Class_Initialize() Set colFiles = New Collection

cTAG() = StrConv("TAG:Int21", vbFromUnicode) End Sub

Public Function EncodeIt() As Boolean On Local Error GoTo EncodeErr

If FileExist(mImageFile) Then

Dim tmpPalette As BITMAPPalette

Call ReadImg_

Call Convert2BinaryArray_(bImgData(), BinaryImg())

DoEvents

RaiseEvent StatusChanged(0, "Pembentukan embed...") OutFile = FreeFile

Open "c:\tmp_C23F41AA.dat" For Binary As #OutFile Put #OutFile, , cTAG()

Put #OutFile, , mFilesAdded RaiseEvent StatusChanged(0, "tunggu...") ReadAttach_

Close #OutFile

ConvertAttach_ Join_Img_Files_

Kill "c:\tmp_C23F41AA.dat" 'delete buffer file RaiseEvent StatusChanged(100, "Selesai!") Else

(14)

Exit Function EncodeErr:

RaiseEvent SomeError(Err.Description) Err.Clear

Close End Function

Public Function DecodeIt() As Boolean

If Not ReadTag_ Then 'melihat apakah ada penyisip RaiseEvent SomeError("Data embed tidak ada") Else

ExtractData_ DecodeIt = True End If

End Function

Public Sub Save2Image() Dim strDone$

If OutputImageFile <> "" Then

RaiseEvent StatusChanged(0, "sedang menyimpan file...")

If Not SaveImg_() Then strDone = "Error penyimpanan" Else strDone = "File sudah disimpan !"

RaiseEvent StatusChanged(100, strDone) Else

RaiseEvent StatusChanged(0, "Citra tidak ada!") End If

End Sub

Private Function SaveImg_() As Boolean Dim I&, J&, xFil&, lngCounter&

Dim maxArr&

On Local Error GoTo SaveImgErr

maxArr = UBound(bImgData()) For J = 0 To UBound(BinaryImg())

bImgData(I) = Bin2Asc(BinaryImg(J)) I = I + 1

If I > maxArr Then Exit For

End If

RaiseEvent StatusChanged(J * 100 / maxArr, "Simpan stego image...")

DoEvents Next J

xFil = FreeFile

Open mOutputImageFile For Binary As #xFil Put #xFil, , BmpHead

Put #xFil, , BmpInfo

For lngCounter = 1 To DeepColor Put #1, , bmpPalette(lngCounter) Next lngCounter

Put #xFil, , bImgData

(15)

Exit Function SaveImgErr:

RaiseEvent SomeError(Err.Description) Err.Clear

End Function

Private Sub ReadAttach_() Dim xFil&, I&, lenBy& Dim It As ClsFile

Dim vData() As Byte, strOut() As Byte

Dim Str3 As String * 3, Str10 As String * 10 Dim strShort$

On Local Error GoTo ReadAttachErr

xFil = FreeFile

RaiseEvent StatusChanged(0, "Pembacaan nilai piksel...") I = 0

For Each It In colFiles

Open It.FileName For Binary As #xFil vData = InputB(LOF(xFil), #xFil) Str3 = It.TypeFile

Str10 = It.FileTitle

I = I + 1

RaiseEvent StatusChanged((I * 100 / mFilesAdded), "Pembacaan nilai piksel..." & Str10)

strOut() = StrConv(Str3, vbFromUnicode) Put #OutFile, , strOut()

Put #OutFile, , It.LenBytes

strOut() = StrConv(Str10, vbFromUnicode) Put #OutFile, , strOut()

Put #OutFile, , vData() DoEvents

Close #xFil Next

Exit Sub

ReadAttachErr:

RaiseEvent SomeError(Err.Description) Err.Clear

End Sub

Private Sub ReadHeadImg_(pFile&) Dim tmpPalette As BITMAPPalette Dim I&

Get #pFile, , BmpHead Get #pFile, , BmpInfo

DeepColor = ((BmpHead.lngBitmapOffset - 54) / Len(tmpPalette)) If DeepColor > 0 Then ReDim bmpPalette(1 To DeepColor)

For I = 1 To DeepColor

Get #pFile, , bmpPalette(I) Next I

End Sub

Private Sub ReadImg_()

(16)

xFil = FreeFile 'menyatakan bit2 yg bs disisipkan/free file Open mImageFile For Binary As #xFil

RaiseEvent StatusChanged(0, "Baca Header...") ReadHeadImg_ xFil

ReDim bImgData(0 To (BmpHead.lngFileSize - BmpHead.lngBitmapOffset) - 1)

Call NilaiPiksel

RaiseEvent StatusChanged(0, "Baca piksel citra...") LenBytes = UBound(bImgData())

For lngCounter = 0 To LenBytes If Not EOF(xFil) Then

Get #xFil, , bytColor

bImgData(lngCounter) = bytColor End If

RaiseEvent StatusChanged(lngCounter * 100 / LenBytes, "Baca nilai piksel citra...")

DoEvents Next lngCounter Close #xFil

End Sub

Private Function ReadTag_() As Boolean Dim binData() As tBits, binTag() As tBits Dim I&, J&, Cur&, bytColor As Byte

Dim strMyTag As String * 9 Dim lenStruct&, xFil& Dim xyTb(0) As tBits

RaiseEvent StatusChanged(0, "Cari header...") lenStruct = 9

ReDim binTag(0 To lenStruct) xFil = FreeFile

Open mImageFile For Binary As #xFil ReadHeadImg_ xFil

lenStruct = 72

ReDim bImgData(0 To lenStruct)

For I = 0 To lenStruct If Not EOF(xFil) Then Get #xFil, , bytColor bImgData(I) = bytColor End If

Next I Close #xFil

Call Convert2BinaryArray_(bImgData(), binData())

lenStruct = UBound(binTag()) Cur = 0

lenStruct = 9

For I = 0 To lenStruct For J = 0 To 7

binTag(I).Bits(J) = binData(Cur).Bits(7) Cur = Cur + 1

Next J

(17)

strMyTag = Binary2String(binTag) ReadTag_ = (strMyTag = "TAG:Int21") End Function

Private Sub ExtractData_()

Dim OutFile&, ImgFile& Dim tmpFile&

Dim dataOut() As Byte Dim BinOut() As tBits

Dim Bytes2Read&, Cur&, I&, J& Dim bytColor As Byte

Dim sTAg$, lFA&, sTF$, lLF&, sNF$

ImgFile& = FreeFile

Open mImageFile$ For Binary As #ImgFile

Call ReadHeadImg_(ImgFile) Call NilaiPiksel

Bytes2Read = LOF(ImgFile) - Loc(ImgFile) ReDim dataOut(0 To Bytes2Read)

For I = 0 To (Bytes2Read) If Not EOF(ImgFile) Then Get #ImgFile, , bytColor dataOut(I) = bytColor End If

Next I Close #ImgFile

Call Convert2BinaryArray_(dataOut(), BinaryImg())

Bytes2Read = UBound(BinaryImg()) ReDim dataOut(0 To Bytes2Read) ReDim BinOut(0 To Bytes2Read) Cur = 0

For I = 0 To (Bytes2Read) For J = 0 To 7

If Cur >= Bytes2Read Then Exit For

BinOut(I).Bits(J) = BinaryImg(Cur).Bits(7) Cur = Cur + 1

Next J

dataOut(I) = Bin2Asc(BinOut(I)) Next I

OutFile = FreeFile

Open "c:\tmp_DD2741C.dat" For Binary As #OutFile Put #OutFile, , dataOut()

Close OutFile OutFile = FreeFile

Open "c:\tmp_DD2741C.dat" For Binary As #OutFile sTAg = ExtractItem_(OutFile, 9, 0, 1)

lFA = ExtractItem_(OutFile, 4, 0, 0) Dim strFile$

Dim It As ClsFile For I = 1 To lFA

(18)

Open strFile For Binary As tmpFile dataOut() = InputB(lLF, OutFile) Put tmpFile, , dataOut()

Close tmpFile

AddFile strFile, sNF, CStr("c0" & I) Next

Close OutFile

Kill "c:\tmp_DD2741C.dat" End Sub

Private Function ExtractItem_(pFile As Long, Bytes2Read As Long, Bytes2Look As Long, RetType As Integer)

Dim Memo() As Byte Dim lLong&

Dim strEnd$

Memo() = InputB(Bytes2Read, pFile) If RetType = 0 Then

CopyMemory lLong, Memo(0), Len(lLong) ExtractItem_ = lLong

ElseIf RetType = 1 Then strEnd = Memo()

ExtractItem_ = StrConv(strEnd, vbUnicode) End If

End Function

Private Sub ConvertAttach_() Dim byt As Byte

Dim LenF&, I&

OutFile = FreeFile

LenF = FileLen("c:\tmp_C23F41AA.dat") ReDim bAttachData(0 To LenF)

Open "c:\tmp_C23F41AA.dat" For Binary As #OutFile Do While Not EOF(OutFile)

Get OutFile, , byt bAttachData(I) = byt I = I + 1

Loop

Close #OutFile End Sub

Private Sub Join_Img_Files_() Dim I&, J&, K&, LenImg&, LenF&

LenImg = UBound(BinaryImg()) LenF = UBound(BinaryAttach()) I = 0

For J = 0 To LenF For K = 0 To 7

BinaryImg(I).Bits(7) = BinaryAttach(J).Bits(K) I = I + 1

Next K

If I >= LenImg Then Exit For

RaiseEvent StatusChanged((I * 100 / LenImg), "Penyisipan embed image --> Cover image...")

DoEvents Next J

(19)

Private Sub Convert2BinaryArray_(Source() As Byte, RetArray() As tBits)

Dim LenArray&, I&

Dim arrBinary() As tBits Dim Bits8 As tBits

LenArray = UBound(Source()) ReDim arrBinary(0 To LenArray)

For I = 0 To LenArray

Bits8 = ByteToBinary(Source(I)) arrBinary(I) = Bits8

RaiseEvent StatusChanged((I * 100 / LenArray), "Konversi Hex to Biner...")

DoEvents Next I

RetArray = arrBinary End Sub

Private Function FileExist(strFile As String) As Boolean Dim Rs$, Tama As Boolean

Dim Tm&

Rs = Dir(strFile) FileExist = (Len(Rs)) End Function

Public Property Get OutputImageFile() As String OutputImageFile = mOutputImageFile

End Property

Public Property Let OutputImageFile(ByVal sNewFile As String) mOutputImageFile = sNewFile

End Property

Private Sub Class_Terminate() Dim tmpClass As ClsFile

For Each tmpClass In colFiles Set tmpClass = Nothing Next

Set colFiles = Nothing End Sub

Public Property Get BytesAdded() As Long BytesAdded = mBytesAdded

End Property

Public Property Get BytesTotal() As Variant BytesTotal = mBytesLimit

End Property

Kode Program Modules :

Option Explicit

Dim RR, RR1 As Single

Dim Bh, Ch, Dh, Eh, Fh As String

(20)

Dim bitLSB() As Single

Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long) As Long

Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Public Type tBits

Bits(0 To 7) As Single End Type

Public bitR As Single Public bitG As Single Public bitB As Single Type winBMPFileHeader

strFileType As String * 2 lngFileSize As Long

bytReserved1 As Integer bytReserved2 As Integer lngBitmapOffset As Long End Type

Type BITMAPINFOHEADER biSize As Long biWidth As Long biHeight As Long biPlanes As Integer byBitCount As Integer biCompression As Long biSizeImage As Long biXPelsPerMeter As Long biYPelsPerMeter As Long biClrUsed As Long

biClrImportant As Long End Type

Type BITMAPPalette lngBlue As Byte lngGreen As Byte lngRed As Byte lngReserved As Byte End Type

Public bolCover As Boolean Public bolEmbed As Boolean Public bolEkstrak As Boolean

Sub NilaiPiksel()

On Error Resume Next Dim NewColor As Long Dim X, Y As Integer Dim R, G, B As Integer Dim Pic1 As PictureBox Dim bChar As Single

Pic1.Picture = frmAdd.TheImage For X = 0 To Pic1.ScaleWidth For Y = 0 To Pic1.ScaleHeight

NewColor = GetPixel(Pic1.hDC, X, Y) R = NewColor And 255

G = (NewColor And 65280) / 256

B = (NewColor And 16711680) / 256 / 256

(21)

If B > 256 Then B = 256 If B < 0 Then B = 0 If G > 256 Then G = 256 If G < 0 Then G = 0

bChar = (R + G + B) / 3

If bolCover = True Then ByteToBinary (bChar) ElseIf bolEmbed = True Then Call ASCII_Embed(bChar) ElseIf bolEkstrak = True Then Call ByteToBinary(bChar) Call BinHex

End If Next Y Next X End Sub

Private Sub GET_COLORS(COLOR As Long, ByRef R As Single, ByRef G As Single, ByRef B As Single)

R = COLOR And RGB(255, 0, 0)

G = Int((COLOR And RGB(0, 255, 0)) / 256)

B = Int(Int((COLOR And RGB(0, 0, 255)) / 256) / 256)

NewColor = COLOR If R > 256 Then R = 256

ElseIf R < 0 Then R = 0

End If

If G > 256 Then G = 256

ElseIf G < 0 Then G = 0

End If

If B > 256 Then B = 256

ElseIf B < 0 Then B = 0

End If

End Sub

Private Sub GET_COLORS_BINER(COLOR As Long, ByRef RR As Single) RR = COLOR

End Sub

Sub ChcSYmbols() Dim q As Integer For q = 0 To 8

If LCase(ASCIIBit) Then bitLSB(q) = Bh

ElseIf UCase(ASCIIBit) Then bitLSB(q) = Ch

ElseIf ASCIIBit = "" Then bitLSB = Dh

(22)

bitLSB(q) = Eh Else

bitLSB(q) = Fh End If

Next q End Sub

Sub ASCII_Embed(ByVal data As Single) Dim strASCII As Single

Dim strBiner As Single If data = 0 Then

strASCII = 30

strBiner = "00110000" ElseIf data = 1 Then strASCII = 31

strBiner = "00110001" ElseIf data = 2 Then strASCII = 32

strBiner = "00110010" ElseIf data = 3 Then strASCII = 33

strBiner = "00110011" ElseIf data = 4 Then strASCII = 34

strBiner = "00110100" ElseIf data = 5 Then strASCII = 35

strBiner = "00110101" ElseIf data = 6 Then strASCII = 36

strBiner = "00110110" ElseIf data = 7 Then strASCII = 37

strBiner = "00110111" ElseIf data = 8 Then strASCII = 38

strBiner = "00111000" ElseIf data = 9 Then strASCII = 39

strBiner = "00111001" ElseIf data = "" Then strASCII = 20

strBiner = "00111001"

End If

Call Insert_Embed End Sub

Sub strASCII()

Dim NewColor As Long Dim X, Y As Integer Dim Pic1 As PictureBox Dim bChar As Single On Error Resume Next

Pic1.Picture = frmAdd.TheImage For X = 0 To Pic1.ScaleWidth For Y = 0 To Pic1.ScaleHeight

GET_COLORS_BINER frmAdd.TheImage.Point(X, Y), RR1 bitLSB(X) = Right(RR1, 5)

(23)

Call BinHex Next Y

Next X End Sub

Sub BinHex()

If LCase(bitLSB) = "11110" Then bitLSB(q) = Eh

ElseIf UCase(bitLSB) = "11101" Then bitLSB(q) = Dh

ElseIf ASCIIBit = "11111" Then bitLSB = Fh

ElseIf ASCIIBit = "00000" Then bitLSB(q) = 0

ElseIf ASCIIBit = "00001" Then bitLSB(q) = 1

ElseIf ASCIIBit = "00010" Then bitLSB(q) = 2

ElseIf ASCIIBit = "00011" Then bitLSB(q) = 3

ElseIf ASCIIBit = "00100" Then bitLSB(q) = 4

ElseIf ASCIIBit = "00101" Then bitLSB(q) = 5

ElseIf ASCIIBit = "00110" Then bitLSB(q) = 6

ElseIf ASCIIBit = "00111" Then bitLSB(q) = 7

ElseIf ASCIIBit = "01000" Then bitLSB(q) = 8

ElseIf ASCIIBit = "01001" Then bitLSB(q) = 9

End If

strembed = strembed & bitLSB(q) End Sub

Function Binary2String(laData() As tBits) Dim ArrEnd() As Byte

Dim strEnd$, I&

ReDim ArrEnd(0 To UBound(laData())) strEnd$ = ""

For I = 0 To UBound(laData())

strEnd = strEnd & Chr(Bin2Asc(laData(I))) Next I

strEnd = VBA.Left$(strEnd, Len(strEnd) - 1) Binary2String = strEnd

End Function

Function Bin2Asc(Bin As tBits) As Integer Dim num As Integer

Dim Fact%, I& num = 0 Fact = 128 For I = 0 To 7

num = num + Bin.Bits(I) * Fact Fact = Fact / 2

(24)

Bin2Asc = num End Function

Function Convert2BinaryArray(laData() As Byte, RetArray() As tBits, olbStatus As Label, ProgBar As ProgressBar)

Dim LenArray&, I&, J&, K& Dim strBin$, Arr() As String Dim arrBinary() As tBits Dim Bits8 As tBits

olbStatus = "Convert Hex to Binary..." LenArray = UBound(laData())

ReDim arrBinary(0 To LenArray) For I = 0 To LenArray

Bits8 = ByteToBinary(laData(I)) K = 1

For J = 0 To 7

arrBinary(I).Bits(J) = Mid(strBin, K, 1) K = K + 1

Next J

ProgBar.Value = I * 100 / LenArray DoEvents

Next I

RetArray = arrBinary End Function

Function ByteToBinary(ByVal data As Byte) As tBits Dim tmpBit As tBits

Dim I As Long, J&

I = &H80 While I

tmpBit.Bits(J) = IIf(data And I, "1", "0") I = I \ 2

J = J + 1 Wend

ByteToBinary = tmpBit End Function

Sub Insert_Embed() Dim ASCII_Sim As String Dim I As Integer

Dim Bin_Data As Single For I = 1 To Len(thedata) If I = 1 Then

ASCII_Sim = "1e" ElseIf thedata = 20 Then ASCII_Sim = "Dh" ElseIf thedata = "" Then ASCII_Sim = "1f" End If

Next I

Call ASCII2Bin(thedata) End Sub

Function ASCII2Bin(ByVal thedata As Byte) As tBits Dim tmpBit As tBits

(25)

Dim xx As Integer Dim yy As Integer I = &H80 '10000000 While I

tmpBit.Bits(J) = IIf(thedata And I, "1", "0") I = I \ 2

J = J + 1 Wend

ByteToBinary = tmpBit

PicCover.Picture = frmAdd.TheImage For X = 0 To PicCover.ScaleWidth For Y = 0 To PicCover.ScaleHeight

PicCover.PSet (X, Y), Right(tmpBit.Bits(J), 5) 'frmAdd.picStego.PSet (X, Y), RGB(0, 255, 10) 'Picture1.PSet (X, Y), RGB(Gray2, Gray2, Gray2) PicCover.Refresh

Next Y Next X

picStego.Picture = PicCover.Picture

For xx = 1 To picStego.Width For yy = 1 To picStego.Height

GET_COLORS picStego.Point(xx, yy), R, G, B bitR = R

Referensi

Dokumen terkait

Public Shared Function GetList( ByVal nama As String )

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click..

Public Property Index As Integer Public Property Status As String Public Property Sender As String Public Property Alphabet As String Public Property Sent

Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load. BukaDB() End Sub

Yang bertanda tangan di bawah ini, menerangkan bahwa Mahasiswa Tugas Akhir Program studi D3 Teknik Informatika:.. Nama :

 Praktek Kerja Lapangan DISPENDA PROVSU (Dinas Pendapatan Daerah. Provinsi Sumatera Utara)

Private Sub Transformation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load. Timer1.Start()

Public lokasiLsb As String Public lokasi2Lsb As String Public besarFileLsb As Long Public besarFile2Lsb As Long Public lokasiEof As String Public lokasi2Eof