Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi Guys Needed code for standard

Status
Not open for further replies.

MAK9974

IS-IT--Management
Apr 11, 2002
145
US
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 &quot;<BR>In Encrypt sSecret=&quot; & 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 &quot;<BR>In For loop Encrypt cipher=&quot; & cipher & &quot;=&quot;
Next
' Response.Write &quot;<BR>Leaving Encrypt cipher=&quot; & cipher & &quot;=&quot;
Encrypt = cipher

End Function





-MAK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top