我只是vb 10的新手,我正在创建一个vigenere密码程序,但我不知道如何在一个按钮中调用一个函数。这是我的代码:
Public Shared Function Encrypt(ByVal cipherTxt As String, ByVal key As String)
Dim encryptedText As String = ""
For i As Integer = 1 To cipherTxt.Length
Dim temp As Integer = AscW(GetChar(cipherTxt, i)) + AscW(GetChar(key, i Mod key.Length + 1))
encryptedText += ChrW(temp)
Next
Return encryptedText
End Function
Public Shared Function Decrypt(ByVal cipherTxt As String, ByVal key As String)
Dim decryptedText As String = ""
For i As Integer = 1 To cipherTxt.Length
Dim temp As Integer = AscW(GetChar(cipherTxt, i)) - AscW(GetChar(key, i Mod key.Length + 1))
decryptedText += ChrW(temp)
Next
Return decryptedText
End Function
有任何帮助吗?谢谢。
答案 0 :(得分:0)
那么你需要做这样的事情
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Encrypt("This is the string to Encrypt", "This is the key")
End Sub
您需要传入文本以加密,这可能来自文本框,而密钥可能是一个私有变量,因此可以进一步采用该阶段。假设TextBox1包含一些您希望加密的文本(并将该加密文本返回到它来自的文本框中;
Private _myKey As String ="This is the key to encrypt & Decrypt"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Text = Encrypt(TextBox1.text, _myKey)
End Sub
相同的基本功能适用于解密。
注意:这不包含错误检查,建议不要以开放方式存储密钥,但这里应该有足够的信息来启动