⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 bmp图像的加密
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "BMP图像加密和解密"
   ClientHeight    =   6705
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   6975
   Icon            =   "Form1.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   6705
   ScaleWidth      =   6975
   StartUpPosition =   3  '窗口缺省
   Begin VB.PictureBox Picture3 
      AutoSize        =   -1  'True
      Height          =   2295
      Left            =   7200
      ScaleHeight     =   149
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   109
      TabIndex        =   7
      Top             =   240
      Width           =   1695
   End
   Begin VB.FileListBox File1 
      Height          =   3690
      Left            =   120
      Pattern         =   "*.bmp"
      TabIndex        =   6
      Top             =   2160
      Width           =   3495
   End
   Begin VB.DirListBox Dir1 
      Appearance      =   0  'Flat
      Height          =   1560
      Left            =   120
      TabIndex        =   5
      Top             =   480
      Width           =   3495
   End
   Begin VB.DriveListBox Drive1 
      Appearance      =   0  'Flat
      Height          =   300
      Left            =   120
      TabIndex        =   4
      Top             =   120
      Width           =   3495
   End
   Begin VB.CommandButton Command2 
      Caption         =   "解密 "
      Height          =   495
      Left            =   3600
      TabIndex        =   3
      Top             =   6120
      Width           =   2055
   End
   Begin VB.CommandButton Command1 
      Caption         =   "加密"
      Height          =   495
      Left            =   1440
      TabIndex        =   2
      Top             =   6120
      Width           =   2055
   End
   Begin VB.PictureBox Picture2 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      ForeColor       =   &H80000008&
      Height          =   2895
      Left            =   3720
      ScaleHeight     =   143.25
      ScaleMode       =   2  'Point
      ScaleWidth      =   155.25
      TabIndex        =   1
      Top             =   3000
      Width           =   3135
   End
   Begin VB.PictureBox Picture1 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      ForeColor       =   &H80000008&
      Height          =   2775
      Left            =   3720
      ScaleHeight     =   183
      ScaleMode       =   0  'User
      ScaleWidth      =   207
      TabIndex        =   0
      Top             =   120
      Width           =   3135
   End
   Begin VB.Label Label1 
      Caption         =   "Label1"
      Height          =   375
      Left            =   120
      TabIndex        =   8
      Top             =   5880
      Width           =   2775
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'***********************************************************************************************************
'BMP图片的加密和解密
'设计编制:田草
'联系方式:caotian1001@sohu.com
'***********************************************************************************************************
Dim ByteArray() As Byte '加密前图片的二进制数组
Dim JiaMiByte() As Byte '加密后图片的二进制数组
'加密图片
Private Sub Command1_Click()
Dim FileName1 As String, FileName2 As String
Dim FileHead As Long
FileName1 = File1.Path + "\" + File1.FileName
FileName2 = App.Path + "\" + File1.FileName + ".bmp"
Open FileName1 For Binary As #1
   sizeoffile = LOF(1)
Close #1
xx = InputBox("请输入除去文件头后文件的大小:", "文件大小")
On Error GoTo errhandle:
FileHead = sizeoffile - xx
i = JiaMi_or_JieMi(FileName1, FileName2, 111, FileHead)
Picture3.Picture = LoadPicture(FileName2)
Picture2.PaintPicture Picture3.Picture, 0, 0, Picture2.Width, Picture2.Height, 0, 0, Picture3.Width, Picture3.Height
Picture3.Picture = Nothing
errhandle:
End Sub

Function JiaMi_or_JieMi(FileName1 As String, FileName2 As String, JiaMiKey As Long, FileHead As Long) As Long

Dim szieoffile As Long

On Error GoTo errorhandle:

Open FileName1 For Binary As #1
   sizeoffile = LOF(1)
   ReDim JiaMiByte(1 To sizeoffile) As Byte
   ReDim ByteArray(1 To sizeoffile) As Byte
   Get #1, , ByteArray
Close #1
For i = 1 To FileHead
JiaMiByte(i) = ByteArray(i)
Next i
For i = FileHead + 1 To sizeoffile
     JiaMiByte(i) = ByteArray(i) Xor (i Mod 255)
Next i
Open FileName2 For Binary As #2
   Put #2, , JiaMiByte
Close #2
errorhandle:
End Function

Private Sub Command2_Click()
Dim FileName1 As String, FileName2 As String
Dim FileHead As Long
FileName1 = File1.Path + "\" + File1.FileName
FileName2 = App.Path + "\" + File1.FileName + ".bmp"
Open FileName1 For Binary As #1
   sizeoffile = LOF(1)
Close #1
xx = InputBox("请输入除去文件头后文件的大小:", "文件大小")
On Error GoTo errhandle:
FileHead = sizeoffile - xx
i = JiaMi_or_JieMi(FileName1, FileName2, 111, FileHead)
Picture3.Picture = LoadPicture(FileName2)
Picture2.PaintPicture Picture3.Picture, 0, 0, Picture2.Width, Picture2.Height, 0, 0, Picture3.Width, Picture3.Height
Picture3.Picture = Nothing
errhandle:
End Sub

Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub

Private Sub File1_Click()
Picture1.Cls
Picture3.Picture = LoadPicture(File1.Path + "\" + File1.FileName)
Set fso = CreateObject("Scripting.FileSystemObject")
Label1.Caption = fso.GetFile(File1.Path + "\" + File1.FileName).Size - 54
Picture1.PaintPicture Picture3.Picture, 0, 0, Picture1.Width, Picture1.Height, 0, 0, Picture3.Width, Picture3.Height
Picture3.Picture = Nothing
End Sub

Private Sub Form_Load()
Picture3.Visible = False
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -