|
Шифрование по алгоритму RC4. |
|
|
Алгоритм синхронного шифрования RC4. Работает очень просто... Использование: функция EnDeCrypt. Ей передаётся текст и пароль.
Dim s(0 To 255) As Integer
Dim kep(0 To 255) As Integer
Public Function EnDeCrypt(plaintxt As String, Password As String) As String
Dim temp As Integer
Dim a As Integer
Dim b As Integer
Dim cipherby As Byte
Dim cipher As String
'Инициализация
'Создание ключа
b = 0
For a = 0 To 255
b = b + 1
If b > Len(Password) Then
b = 1
End If
kep(a) = Asc(Mid$(Password, b, 1))
Next a
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
temp = s(a)
s(a) = s(b)
s(b) = temp
Next a
'Побайтное шифрование
For a = 1 To Len(plaintxt)
cipherby = EnDeCryptSingle(Asc(Mid$(plaintxt, a, 1)))
cipher = cipher & Chr(cipherby)
Next
EnDeCrypt = cipher
End Function
Public Function EnDeCryptSingle(plainbyte As Byte) As Byte
Dim i As Integer
Dim j As Integer
Dim temp As Integer
Dim k As Integer
Dim cipherby As Byte
'Шифрование одного байта
i = (i + 1) Mod 256
j = (j + s(i)) Mod 256
temp = s(i)
s(i) = s(j)
s(j) = temp
k = s((s(i) + s(j)) Mod 256)
cipherby = plainbyte Xor k
EnDeCryptSingle = cipherby
End Function
|
|
|
|
|
|
|