Sto cercando di creare una funzione per criptare una stringa, in modo anche un po' banale, ma mi serve per proteggere un programma che ho creato. La funzione l'ho sviluppate in VB.Net, e funziona perfettamente in entrambe le direzione (codifica e decodifica). Il codice è il seguente:
codice:
    Private hashes As String() = _
    {"vGn%$08@NfXJ&idD}p^9S1]>HL~3A4W7zK#(k.5!çleUb°6?YB=,2£;u:jr[", _
    ".WD$}Kg0CveH>RkMSYç8XE5h6<s&PT=An:*-tjLxq)iOp[G~#B°J,@?dm49%", _
    "tyDe}sm]@FX[9(.L{,IJCZ^WK-r~u)Nd6vUg_VT#n$hG51|?M\çY0Q°7kcB*", _
    ");\cqsaNFrd&ZB(*,KYyz]103QpD%l:|9E8xt§Ti-U@^J5mv7X!n}gbPA/_<", _
    "P_6R*lLzkp3o7%w|h1<!TEmrUB-tQWqn^AcIj)v£N[;\JiCçf.#xZaD=$y,@", _
    "lkqQe]{wXFf^GRC3,ga@=SY&U#:L£4$ZsçdH/P|u§xvIM~r.O%(A5-VJKo6!", _
    "lA-qYd.Mw<zGj){^>xJ[5S46°mXtrBvuEbs]f#cp_kD8yHi&2:VN03/ThçOF", _
    "£FgMZ4t0$/Rjx9nc@^h3LçdB°sCr7_JN§)y{K*5GD[Q]1H=!p?>;a&-#28EO", _
    "}bQ=2£-doKgz{Lc)Gj&5fY;I^V3n#PA/v~uS?ZxXBrtHs°T6:1!]DCmJk[@>", _
    "G6c5n7zOEZJ°o.%0wD]|=UyB@F)MPRt4>Y}8<!v/i:NVmKp;-kA\r*jh£_çe", _
    "iwY#$Q{tq_>Img\k]RM|p&nb)yfL4P/.Z:D,N9x~os-OAvrjW?ç6^BKJ%02;", _
    "0~KRoEu*>TiUxq°}D5geStO#^§sk6PCcYalAQz:2Np%w.(M=H8\3B19Zfj]-", _
    "$*;Yv!:£1Fm>Q§f5Z3lpgD].wM,LRezrUKu4=JkXt2TIqnVO%&}d8y~_{^E)", _
    ":i]WIb%n;E?m7Z2!Kg<,OVfU|TtePJF3LS9R=Gov)}khAsp.d_[#Xq54D0$^", _
    "S;3=!P)U~Dh-:jq°Xo%ramg£fsçvLON4GH?Y[JTx2\yz6Wuk@FlRw#,.$M^V", _
    "?3&iLwW(2Q°k]gzuUAIC4P.!0J8l%$@GNy={jVXZ<be/rM#-6£^,mv)a;ds*", _
    "X)?av*1x#@I.]EAWjPZw^i23,7CNyg°O5MrJfKQ<ko=_m!£p:;lLc$-%RBz~", _
    "T^(7zQ]U#DIRojL1&CJgh%qyp°f>:aw/WVe_b\AS5,!GZ3§ç042{<OE;l$k*", _
    "_1°7jG#=q%msbSOdVw@§T!H<ekJZ?£o)^(}&C$M*tWp/nx]l0:f5P>.~YB|-", _
    "jdJM_P}rc<{UT[,A]Q.omNevK|WVsçLB:>§t$yZ?kzDIRSu£g1b96325nli@", _
    "h5(Ywçf%8eQ°U-@,Ia0j|TtkD<n$6W:?/BS=#_*Ng1Fsmu^){L7HX§Zd\RM!"}

    Public Function Encode(ByVal str As String) As String
        Return _encode(Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(_encode(str))))
    End Function

    Private Function _encode(ByVal str As String) As String
        Dim hashNum As Integer = CInt(Rnd() * (hashes.Length - 1))
        Dim hash As String = hashes(hashNum)

        Dim buffer As String = String.Empty
        For i As Integer = 0 To str.Length - 1
            If hash.Contains(str(i)) Then
                Dim tmp As Integer = hash.Length - 1 - hash.IndexOf(str(i))
                buffer &= hash(tmp)
            Else
                buffer &= str(i)
            End If
        Next
        buffer &= String.Format("{0:00}", hashNum)
        Return buffer
    End Function

    Public Function Decode(ByVal str As String) As String
        Try
            Return _decode(System.Text.ASCIIEncoding.ASCII.GetString(Convert.FromBase64String(_decode(str))))
        Catch ex As Exception
            MessageBox.Show(ex.ToString, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function

    Private Function _decode(ByVal str As String) As String
        Dim hash As String = hashes(str.Substring(str.Length - 2))
        str = str.Substring(0, str.Length - 2)
        Dim buffer As String = String.Empty
        For i As Integer = 0 To str.Length - 1
            If hash.Contains(str(i)) Then
                Dim tmp As Integer = hash.Length - 1 - hash.IndexOf(str(i))
                buffer &= hash(tmp)
            Else
                buffer &= str(i)
            End If
        Next
        Return buffer
    End Function
E su questo non ho problemi. Il problema nasce quando cerco di emulare la stessa funzione in PHP. La mia funzione è la seguente:
Codice PHP:
function encode($str)
{
    return 
_encode(base64_encode(_encode($str)));
}

function 
_encode($str)
{
    
$hashes = array(
        
'vGn%$08@NfXJ&idD}p^9S1]>HL~3A4W7zK#(k.5!çleUb°6?YB=,2£;u:jr[',
        
'.WD$}Kg0CveH>RkMSYç8XE5h6<s&PT=An:*-tjLxq)iOp[G~#B°J,@?dm49%',
        
'tyDe}sm]@FX[9(.L{,IJCZ^WK-r~u)Nd6vUg_VT#n$hG51|?M\çY0Q°7kcB*',
        
');\cqsaNFrd&ZB(*,KYyz]103QpD%l:|9E8xt§Ti-U@^J5mv7X!n}gbPA/_<',
        
'P_6R*lLzkp3o7%w|h1<!TEmrUB-tQWqn^AcIj)v£N[;\JiCçf.#xZaD=$y,@',
        
'lkqQe]{wXFf^GRC3,ga@=SY&U#:L£4$ZsçdH/P|u§xvIM~r.O%(A5-VJKo6!',
        
'lA-qYd.Mw<zGj){^>xJ[5S46°mXtrBvuEbs]f#cp_kD8yHi&2:VN03/ThçOF',
        
'£FgMZ4t0$/Rjx9nc@^h3LçdB°sCr7_JN§)y{K*5GD[Q]1H=!p?>;a&-#28EO',
        
'}bQ=2£-doKgz{Lc)Gj&5fY;I^V3n#PA/v~uS?ZxXBrtHs°T6:1!]DCmJk[@>',
        
'G6c5n7zOEZJ°o.%0wD]|=UyB@F)MPRt4>Y}8<!v/i:NVmKp;-kA\r*jh£_çe',
        
'iwY#$Q{tq_>Img\k]RM|p&nb)yfL4P/.Z:D,N9x~os-OAvrjW?ç6^BKJ%02;',
        
'0~KRoEu*>TiUxq°}D5geStO#^§sk6PCcYalAQz:2Np%w.(M=H8\3B19Zfj]-',
        
'$*;Yv!:£1Fm>Q§f5Z3lpgD].wM,LRezrUKu4=JkXt2TIqnVO%&}d8y~_{^E)',
        
':i]WIb%n;E?m7Z2!Kg<,OVfU|TtePJF3LS9R=Gov)}khAsp.d_[#Xq54D0$^',
        
'S;3=!P)U~Dh-:jq°Xo%ramg£fsçvLON4GH?Y[JTx2\yz6Wuk@FlRw#,.$M^V',
        
'?3&iLwW(2Q°k]gzuUAIC4P.!0J8l%$@GNy={jVXZ<be/rM#-6£^,mv)a;ds*',
        
'X)?av*1x#@I.]EAWjPZw^i23,7CNyg°O5MrJfKQ<ko=_m!£p:;lLc$-%RBz~',
        
'T^(7zQ]U#DIRojL1&CJgh%qyp°f>:aw/WVe_b\AS5,!GZ3§ç042{<OE;l$k*',
        
'_1°7jG#=q%msbSOdVw@§T!H<ekJZ?£o)^(}&C$M*tWp/nx]l0:f5P>.~YB|-',
        
'jdJM_P}rc<{UT[,A]Q.omNevK|WVsçLB:>§t$yZ?kzDIRSu£g1b96325nli@',
        
'h5(Ywçf%8eQ°U-@,Ia0j|TtkD<n$6W:?/BS=#_*Ng1Fsmu^){L7HX§Zd\RM!',
    );

    
$hashIndex mt_rand(0sizeof($hashes) - 1);
    
$hash $hashes[$hashIndex];

    
$buffer '';
    for (
$i 0$i strlen($str); $i++)
    {
        
$indx strpos($hash$str[$i]);
        
//echo $hash[$indx].'
';
        if ($indx !== false)
        {
            $buffer.= $hash[strlen($hash) - 1 - $indx];
        }
        else
        {
            $buffer.= $str[$i];
        }
    }
    if (strlen(strval($hashIndex)) == 1)
    {
        $buffer.= "0$hashIndex";
    }
    else
    {
        $buffer.= "$hashIndex";
    }
    return $buffer;

Questo codice a volte genera delle stringhe che vengono decodificate dal programma in VB.Net senza problemi, altre volte delle lettere sono mancanti o errate. Avete qualche idea su quale possa essere il problema?