Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7418997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:59:03+00:00 2026-05-29T07:59:03+00:00

I need to convert a few lines of PHP code to C#. However, I

  • 0

I need to convert a few lines of PHP code to C#. However, I have only basic knowledge and I don’t understand well the arrays yet.

Here is the code that I need to be converted to C#:

function decode_char($c, $a1, $a2)
{
  $result = $c;
  for($j = 0; $j < count($a1); $j++) {
    if ($c == $a1[$j][0]) {
      $result = $a2[$j][0];
      break;
    }
    if ($c == $a2[$j][0]) {
      $result = $a1[$j][0];
      break;
    }
  }
  return $result;
}

function decode_str($s)
{
  $a1 = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "W", "G", "X", "M", "H", "R", "U", "Z", "I", "D", "=", "N", "Q", "V", "B", "L");
  $a2 = array("b", "z", "a", "c", "l", "m", "e", "p", "s", "J", "x", "d", "f", "t", "i", "o", "Y", "k", "n", "g", "r", "y", "T", "w", "u", "v");

  $result = '';
  for($i = 0; $i < strlen($s); $i++) {
    $result .= decode_char($s[$i], $a1, $a2);
  }
  $result = base64_decode($result);
  return $result;
}

Here’s what I’ve got so far:

public string decode_str(string s)
{
       string[] a1 = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "W", "G", "X", "M", "H", "R", "U", "Z", "I", "D", "=", "N", "Q", "V", "B", "L" };
       string[] a2 = { "b", "z", "a", "c", "l", "m", "e", "p", "s", "J", "x", "d", "f", "t", "i", "o", "Y", "k", "n", "g", "r", "y", "T", "w", "u", "v" };

       string result = "";
       for (int i = 0; i < s.Length; i++)
       {
           result += decode_char(s[i], a1, a2);
       }

           return result;
}

Can someone help with converting decode_char?

Thank you for fast answers. I already did it myself but using strings and not chars, so I will accept an answer tomorrow when I will revise my code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:59:04+00:00Added an answer on May 29, 2026 at 7:59 am

    Try with this:

    char decode_char(char c, string a1, string a2)
    {
        for (int i = 0; i < a1.Length; i++)
        {
            if (c == a1[i]) return a2[i];
            if (c == a2[i]) return a1[i];
        }
        return c;
    }
    string decode_str(string s)
    {
        const string a1 = "0123456789WGXMHRUZID=NQVBL";
        const string a2 = "bzaclmepsJxdftioYkngryTwuv";
        StringBuilder sb = new StringBuilder();
        foreach (char c in s)
            sb.Append(decode_char(c, a1, a2));
        return DecodeFrom64(sb.ToString());
    }
    string DecodeFrom64(string encodedData)
    {
        byte[] encBytes = Convert.FromBase64String(encodedData);
        return Text.Encoding.Unicode.GetString(encBytes);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to convert several Java classes to C#, but I have faced few
I need a few lines of Javascript code that will take a hexadecimal number
I need to convert an object to xml and have gone through few articles
So I have the following assembly language code which I need to convert into
I need to convert the following perl function to php: pack(SSA12AC4L, $id, $loc, $name,
I have an Ajax call written in prototype and need to convert it to
I have quite a few places where I need to bind form controls directly
I have a few huge tables on a production SQL 2005 DB that need
I need to be able to convert user input to [a-z] roman characters ONLY
I need to be able to convert byte arrays to/from other primitive type arrays,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.