Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
Convert Vb.net To Php

Good morning Engineers

This VB.Net code is responsible for encrypting a password

 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

 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

I will be grateful to everyone who can help me find out where I am failing and how I can fix it

Thanks

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

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.

So change this:

$caracteres[$indice] = chr(ord($caracteres[$indice]) + $indice);

To this:

$caracteres[$indice] = chr(ord($caracteres[$indice]) + ($indice + 1));

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda