问题:将一个文本文件挂到一个位图文件后面,;或者分散到位图文件的各个部分,要求是,加密时判断位图文件是否有加密文件,解密时判断是否是加密文件,正确分离文本文件。
  程序要求使用VB实现,我没学过VB,请各位指教,最好有源代码。

解决方案 »

  1.   

    我倒是有VC的源代码.
    你可以用VC做一个dll
    用VB再调用阿
      

  2.   

    '窗体上三个commandbutton,一个picturebox,一个CommonDialog
    '由于savepicture语句只能保存生成bmp格式的文件,目前只能把要加密的文本文件绑定在bmp文件上
    '如果你了解jpg等文件格式,也可以相应修改对jpg等格式文件进行绑定
    '这是最简单的示例,示范怎样将txt格式(当然也可以是其它格式的文件,在程序中稍稍改动一下就行了)的文件绑定在bmp文件尾部
    '如要分散到bmp内部的话,实现起来要麻烦得多
    Option Explicit
    Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    Private Sub Command1_Click()
        On Error GoTo myerr
        CommonDialog1.Filter = "bmp files(*.bmp)|*.bmp"
        CommonDialog1.FileName = ""
        CommonDialog1.CancelError = True
        CommonDialog1.ShowOpen
        Dim picfilename As String
        picfilename = CommonDialog1.FileName
        If picfilename = "" Then Exit Sub
        Dim picfilelen As Long
        picfilelen = FileLen(picfilename)
        Picture1.Picture = LoadPicture(picfilename)
        Dim templen As Long
        SavePicture Picture1.Picture, App.Path + "\temp.bmp"
        templen = FileLen(App.Path + "\temp.bmp")
        Kill App.Path + "\temp.bmp"
        If picfilelen > templen Then
        MsgBox "该文件经过加密处理,不用再加密了!"
        Exit Sub
        End If
        Dim txtfilename As String
        CommonDialog1.Filter = "txt files(*.txt)|*.txt"
        CommonDialog1.CancelError = True
        CommonDialog1.FileName = ""
        CommonDialog1.ShowOpen
        txtfilename = CommonDialog1.FileName
        Dim txtfilelen As Long
        txtfilelen = FileLen(txtfilename)
        Dim mbyte() As Byte
        ReDim mbyte(txtfilelen - 1)
        Open txtfilename For Binary As 1
        Get 1, , mbyte
        Close 1
        Dim nbyte() As Byte
        ReDim nbyte(picfilelen - 1)
        Open picfilename For Binary As 3
        Get 3, , nbyte
        Close 3
        ReDim Preserve nbyte(picfilelen + txtfilelen - 1)
        MoveMemory nbyte(picfilelen), mbyte(0), txtfilelen
        Open picfilename For Binary As 2
        Put 2, , nbyte
        Close 2
        Exit Sub
    myerr:
        Select Case Err.Number
        Case 32755
        MsgBox "请选择一个文件"
        Case 53
        MsgBox "文件不存在或路径错误"
         End Select
    End Sub
    Private Sub Command2_Click()
        On Error GoTo myerr
        CommonDialog1.Filter = "bmp files(*.bmp)|*.bmp"
        CommonDialog1.FileName = ""
        CommonDialog1.CancelError = True
        CommonDialog1.ShowOpen
        Dim picfilename As String
        picfilename = CommonDialog1.FileName
        If picfilename = "" Then Exit Sub
        Dim picfilelen As Long
        picfilelen = FileLen(picfilename)
        Picture1.Picture = LoadPicture(picfilename)
        Dim templen As Long
        SavePicture Picture1.Picture, App.Path + "\temp.bmp"
        templen = FileLen(App.Path + "\temp.bmp")
        Kill App.Path + "\temp.bmp"
        If picfilelen = templen Then
        MsgBox "该文件没有经过加密处理,请加密!"
        Exit Sub
        End If
        Dim txtfilename As String
        CommonDialog1.Filter = "txt files(*.txt)|*.txt"
        CommonDialog1.CancelError = True
        CommonDialog1.FileName = ""
        CommonDialog1.ShowSave
        txtfilename = CommonDialog1.FileName
        Dim txtfilelen As Long
        txtfilelen = picfilelen - templen
        Dim mbyte() As Byte
        ReDim mbyte(txtfilelen - 1)
        Dim nbyte() As Byte
        ReDim nbyte(picfilelen - 1)
        Open picfilename For Binary As 3
        Get 3, , nbyte
        Close 3
        MoveMemory mbyte(0), nbyte(templen + 1), txtfilelen
        Open txtfilename For Binary As 2
        Put 2, , mbyte
        Close 2
        Exit Sub
    myerr:
        Select Case Err.Number
        Case 32755
        MsgBox "请选择一个文件"
        Case 53
        MsgBox "文件不存在或路径错误"
         End Select
    End SubPrivate Sub Command3_Click()
    Unload Me
    End SubPrivate Sub Form_Load()
       Picture1.Visible = False
       Command1.Caption = "加密文件"
       Command2.Caption = "解密文件"
       Command3.Caption = "退出"
    End Sub