⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cod_used2front.bas

📁 21加密算法,用vB语言编写实现,可了解各种加密算法的结构
💻 BAS
字号:
Attribute VB_Name = "Cod_Used2Front"


Option Explicit

Private CharCount(256) As Long
Private Dictionary As String

'This coder will keep track of wich characters are used and place them
'in order at the front of the dictionary
'if all characters are used the dictionary at the end of the coding
'will be the same as the one we started with

Public Sub Used2Front_Coder(ByteArray() As Byte)
    Dim X As Long
    Dim Temp As Byte
    Call Init_Used2Front
    For X = 0 To UBound(ByteArray)
        Temp = ByteArray(X)
        ByteArray(X) = InStr(Dictionary, Chr(Temp)) - 1
        Call update_Model(Temp)
    Next
End Sub

Public Sub Used2Front_DeCoder(ByteArray() As Byte)
    Dim X As Long
    Dim Temp As Byte
    Call Init_Used2Front
    For X = 0 To UBound(ByteArray)
        Temp = ASC(Mid(Dictionary, ByteArray(X) + 1, 1))
        ByteArray(X) = Temp
        Call update_Model(Temp)
    Next
End Sub

Private Sub Init_Used2Front()
    Dim X As Integer
    Dictionary = ""
    For X = 0 To 255
        Dictionary = Dictionary & Chr(X)
        CharCount(X) = 0
    Next
    CharCount(256) = 0
End Sub

Private Sub update_Model(Char As Byte)
    Dim DictPos As Integer
    Dim OldPos As Integer
    Dim Dict1 As String
    Dim Dict2 As String
    Dim X As Integer
    Dim Tel As Integer
'    Dictpos = InStr(Dictionary, Chr(Char))
'    OldPos = Dictpos
    CharCount(Char) = CharCount(Char) + 1
    If CharCount(Char) = 1 Then
        For X = 0 To 255
            If CharCount(X) > 0 Then
                Dict1 = Dict1 & Chr(X)
            Else
                Dict2 = Dict2 & Chr(X)
            End If
        Next
        Dictionary = Dict1 & Dict2
    End If
End Sub


⌨️ 快捷键说明

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