home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form frmMain
- BorderStyle = 1 'Fixed Single
- Caption = "Encrypt String"
- ClientHeight = 2310
- ClientLeft = 45
- ClientTop = 330
- ClientWidth = 3240
- LinkTopic = "Form1"
- MaxButton = 0 'False
- ScaleHeight = 2310
- ScaleWidth = 3240
- StartUpPosition = 1 'CenterOwner
- Begin VB.CommandButton cmdCrypt
- Caption = "Decrypt"
- BeginProperty Font
- Name = "Arial"
- Size = 9
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 255
- Index = 1
- Left = 1160
- TabIndex = 8
- Top = 2040
- Width = 1175
- End
- Begin VB.CommandButton cmdCrypt
- Caption = "Encrypt"
- BeginProperty Font
- Name = "Arial"
- Size = 9
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 255
- Index = 0
- Left = 0
- TabIndex = 7
- Top = 2040
- Width = 1175
- End
- Begin VB.TextBox txtPW
- BeginProperty Font
- Name = "Arial"
- Size = 9.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 315
- Left = 70
- TabIndex = 6
- Top = 1650
- Width = 2200
- End
- Begin VB.Frame frmePW
- Caption = "Password:"
- Height = 590
- Left = 0
- TabIndex = 5
- Top = 1450
- Width = 2340
- End
- Begin VB.Frame frmeMethod
- Caption = "Method:"
- Height = 840
- Left = 2370
- TabIndex = 2
- Top = 1450
- Width = 855
- Begin VB.OptionButton optMethod
- Caption = "2"
- Height = 255
- Index = 1
- Left = 120
- TabIndex = 4
- Top = 480
- Width = 615
- End
- Begin VB.OptionButton optMethod
- Caption = "1"
- Height = 195
- Index = 0
- Left = 120
- TabIndex = 3
- Top = 240
- Value = -1 'True
- Width = 375
- End
- End
- Begin VB.TextBox txtText
- BeginProperty Font
- Name = "Arial"
- Size = 9.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 1160
- Left = 80
- MultiLine = -1 'True
- ScrollBars = 2 'Vertical
- TabIndex = 1
- Top = 220
- Width = 3070
- End
- Begin VB.Frame frmeText
- Caption = "Text To Encrypt/Decrypt:"
- Height = 1455
- Left = 0
- TabIndex = 0
- Top = 0
- Width = 3225
- End
- Attribute VB_Name = "frmMain"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- '**********************************************************
- '* Encrypt String by Joseph Huntley *
- '* joseph_huntley@email.com *
- '* http://joseph.vr9.com *
- '* *
- '* Made: September 28, 1999 *
- '**********************************************************
- '* The forms here are only used to demonstrate how to *
- '* use the function 'EncryptString'. You may copy the *
- '* function into your project for use. If you need any *
- '* help, please e-mail me. *
- '**********************************************************
- Function EncryptString(strString As String, strPassword As String, Optional boolEncrypt As Boolean = True, Optional intMethod As Integer = 1)
- '**********************************************************
- '* Encrypt String by Joseph Huntley *
- '* joseph_huntley@email.com *
- '* http://joseph.vr9.com *
- '**********************************************************
- '* You may use this code freely as long as credit is *
- '* given to the author, and the header remains intact. *
- '**********************************************************
- '--------------------- The Arguments ----------------------
- 'strString - The string you want to encrypt.
- 'strPassword - The password you want to use.
- 'boolEncrypt - True to encrypt. False to decrypt.
- 'intMethod - The encryption type to use.
- '----------------------------------------------------------
- Dim intBuffer As Integer, intPWChar As Integer
- Dim strEndString As String, strChar As String, strEndChar As String
- Dim lngPWChar As Long, lngChar As Long
- Dim sngChar As Single, sngBuf As Single
- If strPassword$ = "" Then
- EncryptString = strString$
- Exit Function
- End If
- If boolEncrypt Then
- For intBuffer% = 1 To Len(strString$)
- strChar$ = Mid$(strString$, intBuffer%, 1)
- intPWChar% = intPWChar% + 1
- If intPWChar% > Len(strPassword$) Then intPWChar% = 1
- lngPWChar& = Asc(Mid$(strPassword$, intPWChar%, 1))
-
- Select Case intMethod%
- Case 1:
- lngChar& = Asc(strChar$) + lngPWChar&
- If lngChar& > 255 Then lngChar& = lngChar& - 255
- strEndChar$ = Chr$(lngChar&) & Chr$(CInt(lngChar& / 2))
- Case 2:
- sngChar! = Asc(strChar$) / 2
- sngBuf! = Asc(strChar$) / 2
- If InStr(CStr(sngChar!), ".") Then
- sngChar! = CSng(Left$(CStr(sngChar!), InStr(CStr(sngChar!), ".") - 1))
- sngBuf! = CSng(Left$(CStr(sngBuf!), InStr(CStr(sngBuf!), ".") - 1)) + 1
- End If
- sngChar! = sngChar! + lngPWChar&
- If sngChar! > 255 Then sngChar! = sngChar! - 255
- strEndChar$ = Chr$(sngChar!) & Chr$(sngBuf!)
- End Select
-
- strEndString$ = strEndString$ & strEndChar$
- Next intBuffer%
- Else
- For intBuffer% = 1 To Len(strString$) Step 2
- strChar$ = Mid$(strString$, intBuffer%, 1)
- intPWChar% = intPWChar% + 1
- If intPWChar% > Len(strPassword$) Then intPWChar% = 1
- lngPWChar& = Asc(Mid$(strPassword$, intPWChar%, 1))
-
- Select Case intMethod%
- Case 1:
- lngChar& = Asc(strChar$) - lngPWChar&
- If lngChar& < 0 Then lngChar& = lngChar& + 255
- strEndChar$ = Chr$(lngChar&)
- Case 2:
- sngChar! = (Asc(strChar$) - lngPWChar&) + Asc(Mid$(strString$, intBuffer% + 1, 1))
- If sngChar! < 0 Then sngChar! = sngChar! + 255
- strEndChar$ = Chr$(sngChar!)
- End Select
-
- strEndString$ = strEndString$ & strEndChar$
- Next intBuffer%
- End If
-
-
- EncryptString = strEndString$
- End Function
- Private Sub cmdCrypt_Click(Index As Integer)
- Dim intMethod As Integer
- If optMethod(0).Value = True Then
- intMethod% = 1
- Else
- intMethod% = 2
- End If
-
-
- txtText.Text = EncryptString(txtText.Text, txtPW.Text, Not CBool(Index), intMethod%)
- 'The expression 'Not CBool(Index)' takes index and converts
- 'it to boolean. Therefore if index will not equal zero, it will return
- 'true, if not false. Since the index for the encrypt button is 0 and 1
- 'for the decrypt button, it going to do the opposite thing. The Not keyword
- 'takes a boolean value and converts it to it's opposite.
- 'For example: 'Not True' will return false.
- End Sub
- Private Sub Command1_Click()
- End Sub
- Private Sub frmeText_DragDrop(Source As Control, X As Single, Y As Single)
- End Sub
-