![]() |
| Ceasar Cipher |
Public Class frmCeasarCipher
Function EncryptDecrypt(ByVal text1 As String, ByVal key As String, ByVal isEncrypt As Boolean) As String
Dim char1 As String
Dim char2 As String
Dim cKey As Byte
Dim strLength As Integer
Dim Result As String = ""
Dim j As Integer = -1
If text1 "" And IsNumeric(key) Then
strLength = text1.Length
For i As Integer = 0 To strLength - 1
char1 = text1.Substring(i, 1)
If j < key.Length - 1 Then
j = j + 1
Else
j = 0
End If
cKey = Val(key.Substring(j, 1))
If isEncrypt Then
char2 = Chr(Asc(char1) + cKey)
Else
char2 = Chr(Asc(char1) - cKey)
End If
Result &= char2
Next
Else
MsgBox("Enter text or key!")
End If
Return Result
End Function
Private Sub btCrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btCrypt.Click
txtResult.Text = EncryptDecrypt(txtText.Text, txtKey.Text, True)
End Sub
Private Sub btDecrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btDecrypt.Click
txtResult.Text = EncryptDecrypt(txtText.Text, txtKey.Text, False)
End Sub

No comments:
Post a Comment