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.