John Davidson

VB.Net Encryption Function to PHP

0 comments
Message:


Ok so i've been learning a couple of weeks about encryption, a friend of mine have an encryption function in VB.Net and he gave it to me so i can transfered it to PHP for some test.


the decryptions works 50% of the times.
Sometimes i get an accurate result and the other i just get some encrypted stuff.
I dont know where i am wrong, i've been playing with these codes the last 2 weeks and i getting me mad.


VB.NET Code


#Region "Llaves"
Private patron_busqueda As String = "3AnB12CDEopFIJKÑcdOP0QRSTU56VWXYZabe9fLMNghi7jklmñqrstuvwx4yz8GH"
Private Patron_encripta As String = "B0CDdE3GHIst8JKL6MNPQR2STUVWX7YZabcÑ5OefghijklFmnñ4opqruv1wxyz9A"
#End Region
Public Function DesEncriptarCadena(ByVal cadena As String) As String
Dim idx As Integer
Dim result As String = ""

For idx = 0 To cadena.Length - 1
result += DesEncriptarCaracter(cadena.Substring(idx, 1), cadena.Length, idx)
Next
Return result
End Function
Private Function DesEncriptarCaracter(ByVal caracter As String, _
ByVal variable As Integer, ByVal a_indice As Integer) As String
Dim indice As Integer

If Patron_encripta.IndexOf(caracter) <> -1 Then
If (Patron_encripta.IndexOf(caracter) - variable - a_indice) > 0 Then
indice = (Patron_encripta.IndexOf(caracter) - variable - a_indice) Mod Patron_encripta.Length
Else
'La línea está cortada por falta de espacio
indice = (patron_busqueda.Length) + ((Patron_encripta.IndexOf(caracter) - variable - a_indice) Mod Patron_encripta.Length)
End If
indice = indice Mod Patron_encripta.Length
Return patron_busqueda.Substring(indice, 1)
Else
Return caracter
End If
End Function

PHP Code


$patron_busqueda = "3AnB12CDEopFIJKNcdOP0QRSTU56VWXYZabe9fLMNghi7jklmnqrstuvwx4yz8GH";
$pb=str_split($patron_busqueda,1);
$pblargo=strlen($patron_busqueda);
$patron_encripta = "B0CDdE3GHIst8JKL6MNPQR2STUVWX7YZabcN5OefghijklFmnn4opqruv1wxyz9A";
$pe=str_split($patron_encripta,1);
$pelargo=strlen($patron_encripta);
$i=0;
$encrypted=str_split($res,1);
$decrypted="";
$res="5555444433332222"
$largo=strlen($res);
while ( $i < $largo) {
$x = array_search($encrypted[$i], $pe);
$x = $x-$largo-$i;
if ($x>=0) {
$z = $pb[$x];
$decrypted=$decrypted.$z;
$i=$i+1;
}else{
$x = $pblargo+($x);
$z = $pb[$x];
$decrypted=$decrypted.$z;
$i=$i+1;
}
}

Any guide/help would be much appreciated



My Answer:
It looks like there are a few issues in your PHP code that may be causing the decryption to not work correctly. Here are some suggestions to help you troubleshoot and fix the issue:

1. Check the variable names: Make sure that the variable names in your PHP code match the ones in the VB.Net code. For example, in your PHP code, you are using $res before it is defined. Make sure to define $res before using it.

2. Check the logic in the decryption function: Double-check the logic in your decryption function to ensure that it matches the logic in the VB.Net code. Pay close attention to the calculations and conditions used to decrypt each character.

3. Debugging: Add some debugging statements to your PHP code to print out the values of variables at different points in the decryption process. This can help you identify where the decryption is going wrong.

4. Test with different inputs: Try decrypting different encrypted strings to see if the issue is specific to a certain input. This can help you narrow down the problem.

5. Compare outputs: Compare the output of your PHP decryption function with the output of the VB.Net decryption function for the same input. This can help you identify any discrepancies in the results.

By following these suggestions and carefully comparing your PHP code with the VB.Net code, you should be able to identify and fix the issues causing the decryption to not work correctly.

Rate this post

5 of 5 based on 3393 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us