W
Wilk Teverbaugh
I am using 4guys RC4 demo and am a little lost on how to store my encrypted
strings. In the demo it shows how to encrypt a string into binary and then
use URLencode to encode it. I'm not sure how to decode the string into
binary so I can then unencrypt my string... I am storing my strings in SQL
server.
Is it possible to just store my strings as binary or do I need to encode
them first? If I need to encode them how can I decode them so I can then
decrypt them?
Any help would be greatly appreciated as I am a little lost.
Dim sbox(255)
Dim key(255)
Sub RC4Initialize(strPwd)
dim tempSwap
dim a
dim b
intLength = len(strPwd)
For a = 0 To 255
key(a) = asc(mid(strpwd, (a mod intLength)+1, 1))
sbox(a) = a
next
b = 0
For a = 0 To 255
b = (b + sbox(a) + key(a)) Mod 256
tempSwap = sbox(a)
sbox(a) = sbox(b)
sbox(b) = tempSwap
Next
End Sub
Function EnDeCrypt(plaintxt, psw)
dim temp
dim a
dim i
dim j
dim k
dim cipherby
dim cipher
i = 0
j = 0
RC4Initialize psw
For a = 1 To Len(plaintxt)
i = (i + 1) Mod 256
j = (j + sbox(i)) Mod 256
temp = sbox(i)
sbox(i) = sbox(j)
sbox(j) = temp
k = sbox((sbox(i) + sbox(j)) Mod 256)
cipherby = Asc(Mid(plaintxt, a, 1)) Xor k
cipher = cipher & Chr(cipherby)
Next
EnDeCrypt = cipher
End Function
dim etime, stime
dim psw, txt
dim strTemp
dim x
etime = 0
stime = 0
psw = "passphrase"
cString = "test string.."
stime = timer
strTemp = EnDeCrypt(cString, psw)
etime = cdbl(timer - stime)
function decode(myStr)
dim k,s1,s2
while inStr(myStr,"&#")
k = inStr(myStr,"&#")
s1= Mid(myStr,k,6)
s2= Mid(s1,3,3)
myStr = replace(myStr,s1,chr(s2))
wend
decode=myStr
end function
for x = 1 to len(strTemp)
newString = newString & right(string(2,"0") & hex(asc(mid(strTemp, x,
1))),2)
next
test1 = EnDeCrypt(cString, psw)
response.write "Binary string = " & test1 & "<br>"
encodedStr = server.urlencode(test1)
response.write "URL encoded string = " & encodedStr & "<br>"
response.write "Decrypted String = " & EnDeCrypt(test1, psw)
strings. In the demo it shows how to encrypt a string into binary and then
use URLencode to encode it. I'm not sure how to decode the string into
binary so I can then unencrypt my string... I am storing my strings in SQL
server.
Is it possible to just store my strings as binary or do I need to encode
them first? If I need to encode them how can I decode them so I can then
decrypt them?
Any help would be greatly appreciated as I am a little lost.
Dim sbox(255)
Dim key(255)
Sub RC4Initialize(strPwd)
dim tempSwap
dim a
dim b
intLength = len(strPwd)
For a = 0 To 255
key(a) = asc(mid(strpwd, (a mod intLength)+1, 1))
sbox(a) = a
next
b = 0
For a = 0 To 255
b = (b + sbox(a) + key(a)) Mod 256
tempSwap = sbox(a)
sbox(a) = sbox(b)
sbox(b) = tempSwap
Next
End Sub
Function EnDeCrypt(plaintxt, psw)
dim temp
dim a
dim i
dim j
dim k
dim cipherby
dim cipher
i = 0
j = 0
RC4Initialize psw
For a = 1 To Len(plaintxt)
i = (i + 1) Mod 256
j = (j + sbox(i)) Mod 256
temp = sbox(i)
sbox(i) = sbox(j)
sbox(j) = temp
k = sbox((sbox(i) + sbox(j)) Mod 256)
cipherby = Asc(Mid(plaintxt, a, 1)) Xor k
cipher = cipher & Chr(cipherby)
Next
EnDeCrypt = cipher
End Function
dim etime, stime
dim psw, txt
dim strTemp
dim x
etime = 0
stime = 0
psw = "passphrase"
cString = "test string.."
stime = timer
strTemp = EnDeCrypt(cString, psw)
etime = cdbl(timer - stime)
function decode(myStr)
dim k,s1,s2
while inStr(myStr,"&#")
k = inStr(myStr,"&#")
s1= Mid(myStr,k,6)
s2= Mid(s1,3,3)
myStr = replace(myStr,s1,chr(s2))
wend
decode=myStr
end function
for x = 1 to len(strTemp)
newString = newString & right(string(2,"0") & hex(asc(mid(strTemp, x,
1))),2)
next
test1 = EnDeCrypt(cString, psw)
response.write "Binary string = " & test1 & "<br>"
encodedStr = server.urlencode(test1)
response.write "URL encoded string = " & encodedStr & "<br>"
response.write "Decrypted String = " & EnDeCrypt(test1, psw)