早上好,工程师们
此vb.net代码负责加密密码
Public Function Encrypt(ByVal clave As String) As String
' Defino variables
Dim indice As Integer = 1
Dim largo As Integer = 0
Dim final As String = ""
largo = Len(Trim(clave))
Dim caracteres(largo) As String
For indice = 1 To largo
caracteres(indice) = Mid(clave, indice, 1)
caracteres(indice) = Chr(Asc(caracteres(indice)) + indice)
final = final & caracteres(indice)
Next indice
Return final
End Function
这就是我用php编写的代码,但由于没有得到预期的结果,我在某些地方失败了
public static function encryption($clave){
$indice = 0;
$largo = 0;
$final = '';
$largo = strlen(trim($clave));
$caracteres = array();
for ($indice; $indice < $largo; $indice++) {
$caracteres[$indice] = substr($clave, $indice, 1);
$caracteres[$indice] = chr(ord($caracteres[$indice]) + $indice);
$final = $final.$caracteres[$indice];
}
return $final;
}
例如,在vb.net中,12345密钥在2468中加密;在php中,相同的密钥在13579中加密
我将感谢所有能够帮助我发现我失败的地方以及如何弥补失败的人
谢谢
1条答案
按热度按时间kjthegm61#
你非常非常接近!你只需要重新加进去
$indice
在vb.net中是一个,但在php中执行数学时是零。因此,改变这一点:
$caracteres[$indice] = chr(ord($caracteres[$indice]) + $indice);
为此:$caracteres[$indice] = chr(ord($caracteres[$indice]) + ($indice + 1));