cryption.bas

来自「这是一个用vb 写的聊天室」· BAS 代码 · 共 84 行

BAS
84
字号
Attribute VB_Name = "Cryption"
'*****************************************
'****** Stole it off some webpage ********
'*****************************************

Option Explicit
Dim s(0 To 255) As Integer 'S-Box
Dim kep(0 To 255) As Integer
Dim i As Integer, j As Integer
'For the file actions


Public Sub RC4ini(Pwd As String)

    Dim temp As Integer, a As Integer, b As Integer
    'Save Password in Byte-Array

    b = 0


    For a = 0 To 255
        b = b + 1


        If b > Len(Pwd) Then
            b = 1
        End If

        kep(a) = Asc(Mid$(Pwd, b, 1))
    Next a

    'INI S-Box



    For a = 0 To 255
        s(a) = a
    Next a

    b = 0


    For a = 0 To 255
        b = (b + s(a) + kep(a)) Mod 256
        ' Swap( S(i),S(j) )

        temp = s(a)
        s(a) = s(b)
        s(b) = temp
    Next a

End Sub

'Only use this routine for short texts



Public Function EnDeCrypt(plaintxt As Variant) As Variant

    Dim temp As Integer, a As Long, i As Integer, j As Integer, k As Integer
    Dim cipherby As Byte, cipher As Variant


    For a = 1 To Len(plaintxt)
        i = (i + 1) Mod 256
        j = (j + s(i)) Mod 256
        ' Swap( S(i),S(j) )

        temp = s(i)
        s(i) = s(j)
        s(j) = temp
        'Generate Keybyte k

        k = s((s(i) + s(j)) Mod 256)
        'Plaintextbyte xor Keybyte

        cipherby = Asc(Mid$(plaintxt, a, 1)) Xor k
        cipher = cipher & Chr(cipherby)
    Next a

    EnDeCrypt = cipher
End Function

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?