All pastes #914180 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-02-22 18:13 UTC
rendered paste body
    Private Function encrypt(ByVal ascii_array() As Integer, ByVal mode As Boolean, Optional ByVal key As Integer = 1) As String
        Dim index As Integer = 0
        Do While index < ascii_array.Length

            If mode = False Then ' to encrypt
                If ((key + ascii_array(index)) > Asc("z")) Then
                    ascii_array(index) = Asc("a") + (key - (Asc("z") - ascii_array(index))) - 1
                ElseIf ((key + ascii_array(index)) > Asc("Z")) Then
                    ascii_array(index) = Asc("A") + (key - (Asc("Z") - ascii_array(index))) - 1
                Else
                    ascii_array(index) += key
                End If
            Else                ' to decrypt
                If ((ascii_array(index) - key) < Asc("A")) Then
                    ascii_array(index) = Asc("Z") - (key - (ascii_array(index) - Asc("A"))) + 1
                ElseIf (Asc(LCase(Chr(ascii_array(index) - key))) < Asc("a")) Then
                    ascii_array(index) = Asc("z") - (key - (ascii_array(index) - Asc("a"))) + 1
                Else
                    ascii_array(index) -= key
                End If
            End If

            encrypt = encrypt + Chr(ascii_array(index))
            index += 1
        Loop
    End Function