Hi Guys
Needed code for standard RC-4 encryption and decryption
I have code for encryption. I need code to decrypting
'create a command button(Command1), text box1(Text1), text box2 (Text2)
Dim m_RC4_KEY
Dim m_SBOX(255)
Dim m_KEY(255)
Private Sub Command1_Click()
Text2.Text = Encrypt((Text1.Text))
End Sub
Sub InitEncr()
' setup base 64 Codecs
m_BASE_64_MAP_INIT = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Dim max
Dim idx
max = Len(m_BASE_64_MAP_INIT)
For idx = 0 To max - 1
' one based string
m_Base64EncMap(idx) = Mid(m_BASE_64_MAP_INIT, idx + 1, 1)
Next
For idx = 0 To max - 1
m_Base64DecMap(Asc(m_Base64EncMap(idx))) = idx
Next
End Sub
Sub InitRC4Key()
' setup RC4 Codecs
m_RC4_KEY = "hahahahahaha"
Dim tempSwap
Dim intLength
Dim a
Dim b
intLength = Len(m_RC4_KEY)
For a = 0 To 255
m_KEY(a) = Asc(Mid(m_RC4_KEY, (a Mod intLength) + 1, 1))
m_SBOX(a) = a
Next
b = 0
For a = 0 To 255
b = (b + m_SBOX(a) + m_KEY(a)) Mod 256
tempSwap = m_SBOX(a)
m_SBOX(a) = m_SBOX(b)
m_SBOX(b) = tempSwap
Next
End Sub
Public Function Encrypt(ByVal sSecret)
Dim temp
Dim a
Dim i
Dim j
Dim k
Dim cipherby
Dim cipher
InitRC4Key
i = 0
j = 0
' Response.Write "<BR>In Encrypt sSecret=" & sSecret
For a = 1 To Len(sSecret)
i = (i + 1) Mod 256
j = (j + m_SBOX(i)) Mod 256
temp = m_SBOX(i)
m_SBOX(i) = m_SBOX(j)
m_SBOX(j) = temp
k = m_SBOX((m_SBOX(i) + m_SBOX(j)) Mod 256)
cipherby = Asc(Mid(sSecret, a, 1)) Xor k
cipher = cipher & Chr(cipherby)
' Response.Write "<BR>In For loop Encrypt cipher=" & cipher & "="
Next
' Response.Write "<BR>Leaving Encrypt cipher=" & cipher & "="
Encrypt = cipher
End Function
-MAK
Needed code for standard RC-4 encryption and decryption
I have code for encryption. I need code to decrypting
'create a command button(Command1), text box1(Text1), text box2 (Text2)
Dim m_RC4_KEY
Dim m_SBOX(255)
Dim m_KEY(255)
Private Sub Command1_Click()
Text2.Text = Encrypt((Text1.Text))
End Sub
Sub InitEncr()
' setup base 64 Codecs
m_BASE_64_MAP_INIT = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Dim max
Dim idx
max = Len(m_BASE_64_MAP_INIT)
For idx = 0 To max - 1
' one based string
m_Base64EncMap(idx) = Mid(m_BASE_64_MAP_INIT, idx + 1, 1)
Next
For idx = 0 To max - 1
m_Base64DecMap(Asc(m_Base64EncMap(idx))) = idx
Next
End Sub
Sub InitRC4Key()
' setup RC4 Codecs
m_RC4_KEY = "hahahahahaha"
Dim tempSwap
Dim intLength
Dim a
Dim b
intLength = Len(m_RC4_KEY)
For a = 0 To 255
m_KEY(a) = Asc(Mid(m_RC4_KEY, (a Mod intLength) + 1, 1))
m_SBOX(a) = a
Next
b = 0
For a = 0 To 255
b = (b + m_SBOX(a) + m_KEY(a)) Mod 256
tempSwap = m_SBOX(a)
m_SBOX(a) = m_SBOX(b)
m_SBOX(b) = tempSwap
Next
End Sub
Public Function Encrypt(ByVal sSecret)
Dim temp
Dim a
Dim i
Dim j
Dim k
Dim cipherby
Dim cipher
InitRC4Key
i = 0
j = 0
' Response.Write "<BR>In Encrypt sSecret=" & sSecret
For a = 1 To Len(sSecret)
i = (i + 1) Mod 256
j = (j + m_SBOX(i)) Mod 256
temp = m_SBOX(i)
m_SBOX(i) = m_SBOX(j)
m_SBOX(j) = temp
k = m_SBOX((m_SBOX(i) + m_SBOX(j)) Mod 256)
cipherby = Asc(Mid(sSecret, a, 1)) Xor k
cipher = cipher & Chr(cipherby)
' Response.Write "<BR>In For loop Encrypt cipher=" & cipher & "="
Next
' Response.Write "<BR>Leaving Encrypt cipher=" & cipher & "="
Encrypt = cipher
End Function
-MAK