Option Explicit On
Public Class Caesar
Private Const intDefaultShift As Integer = 3
Private Const DefaultDirection As ShiftType = ShiftType.Right
Public Enum ShiftType
Right
Left
End Enum
Public Shared Function Encrypt(ByVal strPlainText As String, _
Optional ByVal Direction As ShiftType = DefaultDirection, _
Optional ByVal intShiftValue As Integer = intDefaultShift) As String
Dim strResult As String
Dim intShift As Integer
If Direction = ShiftType.Left Then
intShift = -intShiftValue
Else
intShift = intShiftValue
End If
For I As Integer = 1 To strPlainText.Length
strResult &= Chr(Asc(Mid(strPlainText, I, 1)) + intShift)
Next
Return strResult
End Function
Public Shared Function Decrypt(ByVal strCipherText As String, _
Optional ByVal Direction As ShiftType = DefaultDirection, _
Optional ByVal intShiftValue As Integer = intDefaultShift) As String
Dim strResult As String
Dim intShift As Integer
If Direction = ShiftType.Left Then
intShift = -intShiftValue
Else
intShift = intShiftValue
End If
For I As Integer = 1 To strCipherText.Length
strResult &= Chr(Asc(Mid(strCipherText, I, 1)) - intShift)
Next
Return strResult
End Function
End Class