Simple rot13 encoder in vb.net

前端 未结 3 1698
隐瞒了意图╮
隐瞒了意图╮ 2021-01-29 04:38

I am looking for a simple way to encode an inputted text into Rot13. I am hitting a brick wall at the stage of being able to separate out words into individual characters and in

3条回答
  •  春和景丽
    2021-01-29 05:32

    Just call it once to encode, call it again to decode.

    Private Function ROT13_Encode(ByVal Input As String) As String
    Dim chrs As Char() = Input.ToCharArray()
    Dim ReturnString As String = ""
    Dim CharInt As Integer
    
    For Each Chr As Char In chrs
        CharInt = Asc(Chr)
        If CharInt >= 65 And CharInt <= 77 Then 'A-M
            CharInt += 13
        ElseIf CharInt >= 78 And CharInt <= 90 Then 'M-Z
            CharInt -= 13
        ElseIf CharInt >= 97 And CharInt <= 109 Then 'a-m
            CharInt += 13
        ElseIf CharInt >= 110 And CharInt <= 122 Then 'm-z
            CharInt -= 13
        End If
        ReturnString &= ChrW(CharInt)
    
    Next
    
    Return ReturnString
    End Function
    

提交回复
热议问题