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

📄 encrypt.frm

📁 简单的密码例子
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Encryption"
   ClientHeight    =   3855
   ClientLeft      =   3675
   ClientTop       =   3105
   ClientWidth     =   4815
   ForeColor       =   &H80000008&
   LinkTopic       =   "Form1"
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   3855
   ScaleWidth      =   4815
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton cmdDecrypt 
      Caption         =   "&Decrypt"
      Height          =   375
      Left            =   2520
      TabIndex        =   5
      Top             =   3360
      Width           =   1455
   End
   Begin VB.CommandButton cmdEncrypt 
      Caption         =   "&Encrypt"
      Height          =   375
      Left            =   840
      TabIndex        =   4
      Top             =   3360
      Width           =   1455
   End
   Begin VB.TextBox txtPassword 
      Height          =   285
      Left            =   120
      TabIndex        =   3
      Text            =   "Password"
      Top             =   2880
      Width           =   4575
   End
   Begin VB.TextBox txtText 
      Height          =   2175
      Left            =   120
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   1
      Text            =   "Encrypt.frx":0000
      Top             =   360
      Width           =   4575
   End
   Begin VB.Label Label2 
      Caption         =   "&Password:"
      Height          =   255
      Left            =   120
      TabIndex        =   2
      Top             =   2640
      Width           =   1095
   End
   Begin VB.Label Label1 
      Caption         =   "&Text:"
      Height          =   255
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   1095
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Encrypt - Rudimentary encryption/decryption demo program
'Copyright (c) 1997 SoftCircuits Programming (R)
'Redistributed by Permission.
'
'This Visual Basic 5.0 example program demonstrates a very simple
'encryption/decryption algorithm. Although the algorithm is very
'simple, it makes use of a password to provide a reasonable level of
'security for non-critical applications.
'
'Note: Under some circumstances, it may be possible for the encrypted
'string to include Chr$(0). Visual Basic handles this just fine but
'Windows (and therefore the TextBox control) uses Chr$(0) to signify
'the end of the string. Therefore, programs such as this one that
'store the encrypted data in a text box may end up truncating the
'data. Proper use of this algorithm should involve storing the data
'where all characters are supported such as to a binary file.
'
'This program may be distributed on the condition that it is
'distributed in full and unchanged, and that no fee is charged for
'such distribution with the exception of reasonable shipping and media
'charged. In addition, the code in this program may be incorporated
'into your own programs and the resulting programs may be distributed
'without payment of royalties.
'
'This example program was provided by:
' SoftCircuits Programming
' http://www.softcircuits.com
' P.O. Box 16262
' Irvine, CA 92623
Option Explicit

'Set to True to make the password case-sensitive
#Const CASE_SENSITIVE_PASSWORD = False

Private Sub cmdEncrypt_Click()
    txtText = EncryptText((txtText), txtPassword)
End Sub

Private Sub cmdDecrypt_Click()
    txtText = DecryptText((txtText), txtPassword)
End Sub

'Encrypt text
Private Function EncryptText(strText As String, ByVal strPwd As String)
    Dim i As Integer, c As Integer
    Dim strBuff As String

#If Not CASE_SENSITIVE_PASSWORD Then

    'Convert password to upper case
    'if not case-sensitive
    strPwd = UCase$(strPwd)

#End If

    'Encrypt string
    If Len(strPwd) Then
        For i = 1 To Len(strText)
            c = Asc(Mid$(strText, i, 1))
            c = c + Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1))
            strBuff = strBuff & Chr$(c And &HFF)
        Next i
    Else
        strBuff = strText
    End If
    EncryptText = strBuff
End Function

'Decrypt text encrypted with EncryptText
Private Function DecryptText(strText As String, ByVal strPwd As String)
    Dim i As Integer, c As Integer
    Dim strBuff As String

#If Not CASE_SENSITIVE_PASSWORD Then

    'Convert password to upper case
    'if not case-sensitive
    strPwd = UCase$(strPwd)

#End If

    'Decrypt string
    If Len(strPwd) Then
        For i = 1 To Len(strText)
            c = Asc(Mid$(strText, i, 1))
            c = c - Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1))
            strBuff = strBuff & Chr$(c And &HFF)
        Next i
    Else
        strBuff = strText
    End If
    DecryptText = strBuff
End Function

⌨️ 快捷键说明

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