Iniciar sesiónCrear cuenta

PHP - Encryptado RC4 en PHP

Vista:

Publicado por Emi (2 intervenciones) el 18/11/2007 03:05:09
Hola Amigos.. si pudieran ayudarme en traducirlo el siguiente código que está en VB a PHP.... (se trata de la funcion del Algoritmo Alleged RC4
______________________________________
Function RC4(strPwd, hexText)
Dim arrState(255)
Dim arrKey(255)

intLength = Len(strPwd)
For i = 0 To 255
arrKey(i) = Asc(Mid(strPwd, (i Mod intLength) + 1, 1))
arrState(i) = i
Next

j = 0
For i = 0 To 255
j = (j + arrState(i) + arrKey(i)) Mod 256
temp = arrState(i)
arrState(i) = arrState(j)
arrState(j) = temp
Next

i = 0
j = 0
For k = 1 To Len(hexText) Step 2
i = (i + 1) Mod 256
j = (j + arrState(i)) Mod 256
temp = arrState(i)
arrState(i) = arrState(j)
arrState(j) = temp
n = arrState((arrState(i) + arrState(j)) Mod 256)
bytNum = CByte("&H" & Mid(hexText, k, 2)) Xor n
result = result & Right("0" & Hex(bytNum), 2)
Next
RC4 = result
End Function

Function Text2Hex(strText)
For i = 1 To Len(strText)
hexText = Hex(Asc(Mid(strText, i, 1)))
If Len(hexText) = 1 Then hexText = "0" & hexText
result = result & hexText
Next
Text2Hex = result
End Function

Function Hex2Text(hexText)
intLength = Len(hexText)
flg = False
For i = 1 To Len(hexText) Step 2
If flg Then
flg = False
Else
bytAsc = CByte("&H" & Mid(hexText, i, 2))
If (&H0 <= bytAsc And bytAsc <= &H80) Or _
(&HA0 <= bytAsc And bytAsc <= &HDF) Then
'1????????
strChr = Chr(bytAsc)
ElseIf (&H81 <= bytAsc And bytAsc <= &H9F) Or _
(&HE0 <= bytAsc And bytAsc <= &HFF) Then
'2????????
strChr = Chr(CInt("&H" & Mid(hexText, i, 4)))
flg = True
End If
result = result & strChr
End If
Next
Hex2Text = result
End Function

Function Encode(Pass, Source)
Encode = RC4(Pass, Text2Hex(Source))
End Function

Function Decode(Pass, Source)
Decode = Hex2Text(RC4(Pass, Source))
End Function
Valora esta pregunta
0
Otras secciones de LWP con contenido de PHP