157 lines
3.7 KiB
Plaintext
157 lines
3.7 KiB
Plaintext
Public Class PolyRC4
|
|
|
|
Private Key As String = "sad87x6zucigedsjfguycxtiu4e75689374-w24098sdfhj-324iuysdjfbhsdjf"
|
|
|
|
Sub New(ByVal EncryptionKey As String)
|
|
|
|
Key = EncryptionKey
|
|
|
|
End Sub
|
|
|
|
Public Function Encrypt(ByVal message As String) As String
|
|
|
|
message = XX(message, Key)
|
|
|
|
Dim random As New Random()
|
|
|
|
Dim list1 As New System.Collections.ArrayList(), list2 As New System.Collections.ArrayList()
|
|
|
|
Dim out As String = ""
|
|
|
|
Dim num1 As Integer = random.[Next](1, 10255)
|
|
|
|
For i As Integer = 0 To message.Length - 1
|
|
|
|
Dim num2 As Integer = random.[Next](num1) '(&H7A) + &H44
|
|
|
|
list1.Add(Convert.ToInt32(message(i)) + num2)
|
|
|
|
list2.Add(num2)
|
|
|
|
Next
|
|
|
|
For j As Integer = 0 To message.Length - 1
|
|
|
|
out += ChrW(list1(j)) & ChrW(list2(j))
|
|
|
|
Next
|
|
|
|
Return out
|
|
|
|
End Function
|
|
|
|
Public Function Decrypt(ByVal message As String) As String
|
|
|
|
Dim numArray As Integer() = New Integer(message.Length - 1) {}
|
|
|
|
Dim temp As String = ""
|
|
|
|
For i As Integer = 0 To message.Length - 1
|
|
|
|
numArray(i) = Convert.ToInt32(message(i))
|
|
|
|
Next
|
|
|
|
For j As Integer = 0 To message.Length - 1 Step 2
|
|
|
|
Dim num3 As Integer = numArray(j)
|
|
|
|
Dim num4 As Integer = numArray(j + 1)
|
|
|
|
Dim num5 As Integer = num3 - num4
|
|
|
|
temp = temp + ChrW(num5)
|
|
|
|
Next
|
|
|
|
Return XX(temp, Key)
|
|
|
|
End Function
|
|
|
|
Public Shared Function XX(ByVal message As String, ByVal password As String) As String
|
|
|
|
Dim i As Integer = 0
|
|
|
|
Dim j As Integer = 0
|
|
|
|
Dim cipher As New StringBuilder
|
|
|
|
Dim returnCipher As String = String.Empty
|
|
|
|
Dim sbox As Integer() = New Integer(256) {}
|
|
|
|
Dim key As Integer() = New Integer(256) {}
|
|
|
|
Dim intLength As Integer = password.Length
|
|
|
|
Dim a As Integer = 0
|
|
|
|
While a <= 255
|
|
|
|
Dim ctmp As Char = (password.Substring((a Mod intLength), 1).ToCharArray()(0))
|
|
|
|
key(a) = Microsoft.VisualBasic.Strings.Asc(ctmp)
|
|
|
|
sbox(a) = a
|
|
|
|
System.Math.Max(System.Threading.Interlocked.Increment(a), a - 1)
|
|
|
|
End While
|
|
|
|
Dim x As Integer = 0
|
|
|
|
Dim b As Integer = 0
|
|
|
|
While b <= 255
|
|
|
|
x = (x + sbox(b) + key(b)) Mod 256
|
|
|
|
Dim tempSwap As Integer = sbox(b)
|
|
|
|
sbox(b) = sbox(x)
|
|
|
|
sbox(x) = tempSwap
|
|
|
|
System.Math.Max(System.Threading.Interlocked.Increment(b), b - 1)
|
|
|
|
End While
|
|
|
|
a = 1
|
|
|
|
While a <= message.Length
|
|
|
|
Dim itmp As Integer = 0
|
|
|
|
i = (i + 1) Mod 256
|
|
|
|
j = (j + sbox(i)) Mod 256
|
|
|
|
itmp = sbox(i)
|
|
|
|
sbox(i) = sbox(j)
|
|
|
|
sbox(j) = itmp
|
|
|
|
Dim k As Integer = sbox((sbox(i) + sbox(j)) Mod 256)
|
|
|
|
Dim ctmp As Char = message.Substring(a - 1, 1).ToCharArray()(0)
|
|
|
|
itmp = Asc(ctmp)
|
|
|
|
Dim cipherby As Integer = itmp Xor k
|
|
|
|
cipher.Append(Chr(cipherby))
|
|
|
|
System.Math.Max(System.Threading.Interlocked.Increment(a), a - 1)
|
|
|
|
End While
|
|
|
|
returnCipher = cipher.ToString
|
|
|
|
cipher.Length = 0
|
|
|
|
Return returnCipher
|
|
|
|
End Function
|
|
|
|
End Class |