用XOR是简单.
每个文件分开处理会方便些.

解决方案 »

  1.   

    你可以参考一下RSA或DES加密方法,到网上SEARCH一下
      

  2.   

    VERSION 5.00
    Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
    Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
    Begin VB.Form Form1 
       Caption         =   "Form1"
       ClientHeight    =   3195
       ClientLeft      =   60
       ClientTop       =   345
       ClientWidth     =   4680
       LinkTopic       =   "Form1"
       ScaleHeight     =   3195
       ScaleWidth      =   4680
       StartUpPosition =   3  '窗口缺省
       Begin MSComctlLib.ProgressBar ProgressBar1 
          Height          =   255
          Left            =   480
          TabIndex        =   5
          Top             =   1920
          Visible         =   0   'False
          Width           =   3735
          _ExtentX        =   6588
          _ExtentY        =   450
          _Version        =   393216
          Appearance      =   1
       End
       Begin VB.TextBox Text4 
          Height          =   375
          IMEMode         =   3  'DISABLE
          Left            =   2520
          PasswordChar    =   "*"
          TabIndex        =   4
          Top             =   1200
          Width           =   1575
       End
       Begin VB.TextBox Text3 
          Height          =   375
          IMEMode         =   3  'DISABLE
          Left            =   600
          PasswordChar    =   "*"
          TabIndex        =   3
          Top             =   1200
          Width           =   1575
       End
       Begin VB.CommandButton Btnok 
          Caption         =   "&OK"
          Height          =   375
          Left            =   1800
          TabIndex        =   2
          Top             =   2400
          Width           =   1095
       End
       Begin MSComDlg.CommonDialog Clg1 
          Left            =   120
          Top             =   2400
          _ExtentX        =   847
          _ExtentY        =   847
          _Version        =   393216
       End
       Begin VB.TextBox Text2 
          Height          =   495
          Left            =   2640
          MultiLine       =   -1  'True
          TabIndex        =   1
          Text            =   "Jm.frx":0000
          Top             =   240
          Width           =   1455
       End
       Begin VB.TextBox Text1 
          Height          =   495
          Left            =   600
          MultiLine       =   -1  'True
          TabIndex        =   0
          Text            =   "Jm.frx":0006
          Top             =   240
          Width           =   1575
       End
    End
    Attribute VB_Name = "Form1"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    Private Type FILETIME
            dwLowDateTime As Long
            dwHighDateTime As Long
    End TypePrivate Type WIN32_FIND_DATA
            dwFileAttributes As Long
            ftCreationTime As FILETIME
            ftLastAccessTime As FILETIME
            ftLastWriteTime As FILETIME
            nFileSizeHigh As Long
            nFileSizeLow As Long
            dwReserved0 As Long
            dwReserved1 As Long
            cFileName As String * 260
            cAlternate As String * 14
    End TypePrivate Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As LongPrivate Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As LongPrivate Sub Command1_Click()End SubPrivate Sub Btnok_Click()
    If Text1.Text = "" Then
    beep
    MsgBox "必须有源文件名!", vbQuestion, "注意:"
    Text1.SetFocus
    Exit Sub
    End If
    If Text2.Text = "" Then
    beep
    MsgBox "必须有目标文件名!", vbQuestion, "注意:"
    Text1.SetFocus
    Exit Sub
    End If
    If Text1.Text = Text2.Text Then
    beep
    MsgBox "源文件和目标文件不能同名", vbQuestion, "注意:"
    Text1.SetFocus
    Exit Sub
    End If
    If Text3.Text <> Text4.Text Then
    beep
    MsgBox "确认密码不对"
    Text3.SetFocus
    Exit Sub
    End If
    Dim i As Long
    Dim Length As Integer
    Dim Encode As Long
    Length = Len(Text3.Text)
    If Length = 0 Then
    Encode = -30
    Else
    For i = 1 To Length
    Encode = Encode + Asc(Mid(Text3.Text, i, 1)) * 256 * i
    Next i
    Encode = -Encode
    End If
    Dim Fn1 As Long
    Dim Fn2 As Long
    Fn1 = FreeFile
    Open Text1.Text For Binary Access Read As #Fn1
    Fn2 = FreeFile
    Open Text2.Text For Binary Access Write As #Fn2
    Form1.MousePointer = 11
    ProgressBar1.Visible = True
    Dim Flength As Long
    Dim Size As Long
    Dim Byteblock() As Byte
    Dim Position As Long
    Dim J As Long
    Flength = LOF(Fn1)
    Size = 32768
    Position = 0
    Rnd (Encode)
    Do While Position < Flength
    If Flength - Position < Size Then Size = Flength - Position
    ReDim Byteblock(1 To Size)
    Get #Fn1, Position + 1, Byteblock
    For J = 1 To Size
    Byteblock(J) = Byteblock(J) Xor Int(Rnd * 256)
    Next J
    Put #Fn2, Position + 1, Byteblock
    Position = Position + Size
    ProgressBar1.Value = Int(Position / Flength * 100)
    Loop
    Close Fn1, Fn2
    beep
    If Cb_del Then DeleteFile (Text3.Text)
    ProgressBar1.Visible = False
    Form1.MousePointer = 0
    MsgBox "加密/解密完毕!", vbOKOnly, "注意:"
    End Sub
    Private Sub Text1_DblClick()
    Clg1.DialogTitle = "打开源文件名:"
    Clg1.Filter = "所有文件(*.*)|*.*|*.JM文件|*.JM"
    Clg1.ShowOpen
    If Clg1.FileName <> "" Then
    Dim Length As Integer
    Dim exname As String
    Length = Len(Clg1.FileName)
    exname = Mid(Clg1.FileName, Length - 2, 3)
    Text1.Text = Clg1.FileName
     If UCase(exname) = ".JM" Then
     Text2.Text = Mid(Clg1.FileName, 1, Length - 3)
     
    Else Text2.Text = Clg1.FileName + ".JM"
    End If
    End If
    End SubPrivate Sub Text2_DblClick()
    Clg1.DialogTitle = "打开目标文件名:"
    Clg1.Filter = "All files(*.*)|*.*"
    Clg1.ShowOpen
    If Clg1.FileName <> "" Then
    Text2.Text = Clg1.FileName + ".JM"
    End If
    End Sub