pjordanna
asked on
RC4 encryption algo bit level question
Hi Experts,
I am using the functions below to provide an RC4 encryption to some sensitive fields in a website. I have the following question:
On the following line:
dim ET_RC4_40bitKey : ET_RC4_40bitKey="s0W3a" '*** Only 5 characters allowed in UK (40-bit encryption law)
The 40 bit key is defined. It appears to me that the encryption level is set at 40 bit because there are five characters in the encryption key. Is this correct? and if so how do I encrease the encryption to 128 bit?
Basically I am trying to work out the formula for #characters to encryption bit level.
Any ideas?
Thanks,
PJORDANNA
'*** Arrays for the RC4 Encryptions algorithms
Dim RC4_sbox(255)
Dim RC4_keyArray(255)
dim ET_RC4_40bitKey : ET_RC4_40bitKey="s0W3a" '*** Only 5 characters allowed in UK (40-bit encryption law)
Sub RC4Initialize(strPwd)
'**** This routine called by RC4EnDeCrypt function. Initializes the RC4_sbox and the RC4_keyArray array.
dim tempSwap
dim a
dim b
intLength = len(strPwd)
For a = 0 To 255
RC4_keyArray(a) = asc(mid(strpwd, (a mod intLength)+1, 1))
RC4_sbox(a) = a
next
b = 0
For a = 0 To 255
b = (b + RC4_sbox(a) + RC4_keyArray(a)) Mod 256
tempSwap = RC4_sbox(a)
RC4_sbox(a) = RC4_sbox(b)
RC4_sbox(b) = tempSwap
Next
End Sub
Function RC4EnDeCrypt(plaintxt, psw)
'*** Performs the encrption/decryption
'*** Note using more than a 5 character password would be illegal in the UK - only 40 bit encryption allowed
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 + RC4_sbox(i)) Mod 256
temp = RC4_sbox(i)
RC4_sbox(i) = RC4_sbox(j)
RC4_sbox(j) = temp
k = RC4_sbox((RC4_sbox(i) + RC4_sbox(j)) Mod 256)
cipherby = Asc(Mid(plaintxt, a, 1)) Xor k
cipher = cipher & Chr(cipherby)
Next
RC4EnDeCrypt = cipher
End Function
function charStrToHexCodes(charStr) '*** generates a hex byte string from a character string
charStrToHexCodes=""
for qq = 1 to len(charStr)
charStrToHexCodes=charStrT oHexCodes & right(string(2,"0") & hex(asc(mid(charStr, qq, 1))),2)
next
end function
function hexCodesToCharStr(hexCodes ) '*** generates a character string from a hex byte string
dim i
hexCodesToCharStr=""
if len(hexCodes)/2 <> Int(len(hexCodes)/2) then exit function
for i=1 to len(hexCodes)-1 step 2
hexCodesToCharStr=hexCodes ToCharStr& Chr(hexByt eToDecimal (Mid(hexCo des,i,2)))
next
end function
function hexDigitToDecimal(digit) '*** Converts a single hex digit to decimal, returns -1 if not possible
select case digit
case "0","1","2","3","4","5","6 ","7","8", "9"
hexDigitToDecimal=CInt(dig it)
case "A","a"
hexDigitToDecimal=10
case "B","b"
hexDigitToDecimal=11
case "C","c"
hexDigitToDecimal=12
case "D","d"
hexDigitToDecimal=13
case "E","e"
hexDigitToDecimal=14
case "F","f"
hexDigitToDecimal=15
case else
hexDigitToDecimal=-1
end select
end function
function hexByteToDecimal(byteStr) '*** Converts a hex byte to decimal, returns -1 if not possible
if (len(byteStr)<>2 or hexDigitToDecimal(Left(byt eStr,1))=- 1 or hexDigitToDecimal(Right(by teStr,1))= -1) then
hexByteToDecimal=-1
exit function
end if
hexByteToDecimal=hexDigitT oDecimal(L eft(byteSt r,1))*16+h exDigitToD ecimal(Rig ht(byteStr ,1))
end function
I am using the functions below to provide an RC4 encryption to some sensitive fields in a website. I have the following question:
On the following line:
dim ET_RC4_40bitKey : ET_RC4_40bitKey="s0W3a" '*** Only 5 characters allowed in UK (40-bit encryption law)
The 40 bit key is defined. It appears to me that the encryption level is set at 40 bit because there are five characters in the encryption key. Is this correct? and if so how do I encrease the encryption to 128 bit?
Basically I am trying to work out the formula for #characters to encryption bit level.
Any ideas?
Thanks,
PJORDANNA
'*** Arrays for the RC4 Encryptions algorithms
Dim RC4_sbox(255)
Dim RC4_keyArray(255)
dim ET_RC4_40bitKey : ET_RC4_40bitKey="s0W3a" '*** Only 5 characters allowed in UK (40-bit encryption law)
Sub RC4Initialize(strPwd)
'**** This routine called by RC4EnDeCrypt function. Initializes the RC4_sbox and the RC4_keyArray array.
dim tempSwap
dim a
dim b
intLength = len(strPwd)
For a = 0 To 255
RC4_keyArray(a) = asc(mid(strpwd, (a mod intLength)+1, 1))
RC4_sbox(a) = a
next
b = 0
For a = 0 To 255
b = (b + RC4_sbox(a) + RC4_keyArray(a)) Mod 256
tempSwap = RC4_sbox(a)
RC4_sbox(a) = RC4_sbox(b)
RC4_sbox(b) = tempSwap
Next
End Sub
Function RC4EnDeCrypt(plaintxt, psw)
'*** Performs the encrption/decryption
'*** Note using more than a 5 character password would be illegal in the UK - only 40 bit encryption allowed
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 + RC4_sbox(i)) Mod 256
temp = RC4_sbox(i)
RC4_sbox(i) = RC4_sbox(j)
RC4_sbox(j) = temp
k = RC4_sbox((RC4_sbox(i) + RC4_sbox(j)) Mod 256)
cipherby = Asc(Mid(plaintxt, a, 1)) Xor k
cipher = cipher & Chr(cipherby)
Next
RC4EnDeCrypt = cipher
End Function
function charStrToHexCodes(charStr)
charStrToHexCodes=""
for qq = 1 to len(charStr)
charStrToHexCodes=charStrT
next
end function
function hexCodesToCharStr(hexCodes
dim i
hexCodesToCharStr=""
if len(hexCodes)/2 <> Int(len(hexCodes)/2) then exit function
for i=1 to len(hexCodes)-1 step 2
hexCodesToCharStr=hexCodes
next
end function
function hexDigitToDecimal(digit) '*** Converts a single hex digit to decimal, returns -1 if not possible
select case digit
case "0","1","2","3","4","5","6
hexDigitToDecimal=CInt(dig
case "A","a"
hexDigitToDecimal=10
case "B","b"
hexDigitToDecimal=11
case "C","c"
hexDigitToDecimal=12
case "D","d"
hexDigitToDecimal=13
case "E","e"
hexDigitToDecimal=14
case "F","f"
hexDigitToDecimal=15
case else
hexDigitToDecimal=-1
end select
end function
function hexByteToDecimal(byteStr) '*** Converts a hex byte to decimal, returns -1 if not possible
if (len(byteStr)<>2 or hexDigitToDecimal(Left(byt
hexByteToDecimal=-1
exit function
end if
hexByteToDecimal=hexDigitT
end function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Any questions or problems, just let me know.
Keep in mind that you can use the MD5 and 256 security algoritms for anything not just login stuff.