Attribute VB_Name = "Encryption"
Option Explicit

Public Function SHR(PlainText As String) As String
    Dim I As Integer, C As Byte, A As String, t As Byte

    t = Asc(Right(PlainText, 1)) And 1
    For I = 1 To Len(PlainText)
        C = Asc(mID(PlainText, I, 1))
        A = A + Chr((C \ 2) Or (t * 128))
        t = C And 1
    Next

    SHR = A
End Function

Public Function SHL(PlainText As String) As String
    Dim I As Integer, C As Byte, A As String, t As Byte

    t = Asc(Left(PlainText, 1)) And 128
    For I = Len(PlainText) To 1 Step -1
        C = Asc(mID(PlainText, I, 1))
        A = Chr((C * 2) And 255 Or (t \ 128)) + A
        t = C And 128
    Next

    SHL = A
End Function

Public Function Cipher(Key As Long, PlainText As String) As String
    'Cipher = PlainText: Exit Function
    Dim O As String, I As Integer

    Rnd -1: Randomize Key
    For I = 1 To Len(PlainText)
        O = O + Chr(Asc(mID(PlainText, I, 1)) Xor (256 * Rnd))
    Next

    Cipher = O
End Function

Public Function pwEncryption(PlainText As String) As String
    Dim L As Long, Factor As Integer, Char As Byte, O As String

    If Len(PlainText) = 1 Then Exit Function

    For L = 1 To Len(PlainText)
        Factor = Factor Xor Asc(mID(PlainText, L, 1))
    Next

    For L = 1 To Len(PlainText)
        Char = CByte(Asc(mID(PlainText, L, 1)) Xor Factor)
        O = O & Chr(CLng(Char))
        Factor = (Factor Xor (CInt(Char) * (2 ^ (CInt(Char) And 3)))) And &HFF
    Next

    pwEncryption = O
End Function
