[英]Convert Vb.net To Php
Good morning Engineers早上好工程师
This VB.Net code is responsible for encrypting a password这个 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
and this would be the code in php that I did but I'm failing somewhere since I don't get the desired result这将是我在 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;
}
an example would be that in VB.Net the 12345 key is encrypted in 2468: and in PHP the same key is encrypted in 13579例如,在 VB.Net 中,12345 密钥在 2468 中加密:而在 PHP 中,相同的密钥在 13579 中加密
I will be grateful to everyone who can help me find out where I am failing and how I can fix it我将感谢所有可以帮助我找出我失败的地方以及如何解决它的人
Thanks谢谢
You are very, very close!你非常非常接近! You just need to re-add back in that $indice
is one-based in VB.Net but zero-based in PHP when you are performing math.您只需要重新添加$indice
在 VB.Net 中是基于 1 的,但在执行数学运算时在 PHP 中是基于 0 的。
So change this:所以改变这个:
$caracteres[$indice] = chr(ord($caracteres[$indice]) + $indice);
To this:对此:
$caracteres[$indice] = chr(ord($caracteres[$indice]) + ($indice + 1));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.