在vb.net中调用类和私有函数的帮助 [英] Help for calling Class and private function in vb.net
问题描述
你好,
我是编程方面的新手,因此为了理解编程,我决定为每个功能构建一个项目.
这里有crypt/decrypt部分,我想我已经删除了所有crypt的行,因为il只会解密密码: 2945D7F0F653C2EDFF
我已经删除了包含Chr(4)的行,从而减少了代码的数量,因为该代码将占用很多行:S
请您帮忙了解如何在主子菜单中调用我的Function getPassword吗?
感谢您的进一步帮助:)
Hello,
I''m a big newbie in programming so in order to understand a programm i have decided to build a project for each function.
Here there is the crypt/decrypt part, i think i have delete all crypt''s lines because il would just decrypt the password: 2945D7F0F653C2EDFF
I have reduce the code by deleting lines wich contain Chr(4)... cause the code will take lot of lines :S
I ask your help to understand how to call my Function getPassword in the main sub ?
Thanks for your futher help :)
Module Module1
Sub Main()
Console.WriteLine("hello")
End Sub
Public Class Password
'' Keyarray, where the Xor-Keys are stored (To compile, use 0 to 999, for debugging use 0 to 25!)
Const debugging As Boolean = True
Private keyarr(0 To 999) As String
'' Keyindex is used to find the Xor-Key in the Keyarray
Public keyindex As Integer = 0
'' Stores the encrypted password
Public EncryptedPassword As String = "2945D7F0F653C2EDFF "
'' Initiates the Keyarray
Public Sub New()
Me.keyarr(0) = Chr(35) &
''''
''''[...]
''''
''End Sub
''Public Sub fake()
keyarr(26) = Chr(4) &
''''
''''[...]
''''
End Sub
''This Function decrypts a password. The Function takes the Password and the KeyIndex. Encryption will be done with an Xor operation, and the result will be HEX-encoded, so the result is a string
Private Function dec(ByVal Hex As String, ByVal keyindex As Integer) As String
''lenght of the password
Dim Lenght As Integer
''The whole key, which will be used to encrypt the key. This key will be shorten to the needed lenght, and then be stored in the xorwith-variable.
Dim Key As String
''The result, as cleartext
Dim Result As String = ""
''Counter Variable
Dim pwPosition As Integer
''This is set to the numeric value of the character which is going to be xored against the key
Dim intXorValueHex As Short
''This is set to the numeric value of the character which is going to be xored against the Hex
Dim intXorValueKey As Short
''String for Temporary Use
Dim TempStr As String
''Integer for Temporary Use
Dim TempInt As Integer
Key = keyarr(keyindex)
If Me.EncryptedPassword.Length > 0 Then
Try
''get the lenght of the password, it''s half of the hex-lenght
Lenght = Hex.Length / 2
''As long as we are inside the Password
For pwPosition = 1 To Lenght Step 1
''Get the Char from the Key and the Hex as integer, at which position we are.
intXorValueHex = CInt("&H" & Mid(Hex, pwPosition * 2 - 1, 2))
intXorValueKey = Asc(Mid(Key, pwPosition, 1))
''XOR this characters against eachother
TempInt = (intXorValueHex Xor intXorValueKey)
''Write the Char as Hex into the TempStr
TempStr = Chr(TempInt)
''Append the two chars of the Hex to the result-string
Result &= TempStr
Next
Catch ex As System.Exception
''MsgBox(ex.Message & vbNewLine & "Most possible, the Password was unencrypted")
End Try
End If
Return Result
End Function
Public Function getPassword() As String
'' Function which returns the Password as string
Return Me.dec(EncryptedPassword, keyindex)
End Function
End Class
End Module
推荐答案
Dim thePassword As New Password
thePassword.getPassword()
这篇关于在vb.net中调用类和私有函数的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!