2016-02-15 25 views
1

我只是在vb 10中新增了一个,我正在创建一个vigenere密码程序,但我不知道如何调用按钮中的函数。这里是我的代码:如何在VB中调用按钮中的函数10

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

那么你需要做这样的事情

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 

相同的基本功能,适用于解密

注意:这包含没有错误检查,并且以开放的方式储存你的钥匙是不被推荐的,但是这里应该有足够的空间来让你开始。

相关问题