Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!