Oppure

Loading
24/10/13 22:09
AxelMtE
Salve a tutti,
Questa è una funzione che esisteva nel set della Borland sulle funzioni di Encrypt e Crypt..
vorrei portarla in c#...
Ho provato a convertirla da solo ma credo di aver fatto degli errori o comunque non funziona...
Vi posto il codice prima In Delphi e poi in C#...se qualcuno fosse così gentile da aiutarmi...grazie in anticipo:)
 Codice Sorgente in Delphi
function Decrypt(hash: String; QIP: String = ''): String;
var
i: Byte;
Chr,a,b,c: DWORD;
begin
Result:= '';
if (QIP = '') then begin
a:= AC3; b:= 421; c:= CEB;
end else begin
a:= B5F; b:= $A8C3; c:= E9;
for i:= 1 to Length(QIP) do c:= c + Ord(QIP[i]);
end;

for i:= 1 to Length(hash) do begin
Chr:= Ord(hash[i]);
Result:= Result + Char(Byte(Chr xor Byte(a shr )));
a:= ((a + Chr) * b) + c;
end;
end;


e questa è la mia...sigh 8-|...traduzione in c#
 Codice sorgente in C#
 private static string Decrypt(string hash, string QIP)
        {
            
            string result = string.Empty;
               
                byte i;
                uint a, b, c;
                if (QIP == "")
                {
                    a = 6851; //1ac3
                    b = 230433; // 38421
                    c = 412907; // 64CEB
                }
                else
                {
                    // B5F; b:= $A8C3; c:= E9;
                    a = 7007;
                    b = 43203;
                    c = 1001;

                    for (i = 1; i < QIP.Length; )
                    {
                        c = c + (uint)QIP[i];
                        i++;
                    }
                    
                }
                
                for (i = 0; i < hash.Length; )
                {
                    chr = chr + (uint)hash[i];
                    i++;
                }
                Console.WriteLine((char)chr);
                result = result + (char)((byte)(chr ^ (byte)(a >> 8)));
                Console.WriteLine(result);
                a = ((a + chr) * b) + c;

                return result;
        }

Spero nell'aiuto di qualcuno...sono bloccato
Ultima modifica effettuata da AxelMtE 24/10/13 22:11
aaa
24/10/13 22:12
AxelMtE
Postato originariamente da AxelMtE:

Salve a tutti,
Questa è una funzione che esisteva nel set della Borland sulle funzioni di Encrypt e Decrypt..
vorrei portarla in c#...
Ho provato a convertirla da solo ma credo di aver fatto degli errori o comunque non funziona...
Vi posto il codice prima In Delphi e poi in C#...se qualcuno fosse così gentile da aiutarmi...grazie in anticipo:)
 Codice Sorgente in Delphi
function Decrypt(hash: String; QIP: String = ''): String;
var
i: Byte;
Chr,a,b,c: DWORD;
begin
Result:= '';
if (QIP = '') then begin
a:= AC3; b:= 421; c:= CEB;
end else begin
a:= B5F; b:= $A8C3; c:= E9;
for i:= 1 to Length(QIP) do c:= c + Ord(QIP[i]);
end;

for i:= 1 to Length(hash) do begin
Chr:= Ord(hash[i]);
Result:= Result + Char(Byte(Chr xor Byte(a shr )));
a:= ((a + Chr) * b) + c;
end;
end;


e questa è la mia...sigh 8-|...traduzione in c#
 Codice sorgente in C#
 private static string Decrypt(string hash, string QIP)
        {
            
            string result = string.Empty;
               
                byte i;
                uint a, b, c;
                if (QIP == "")
                {
                    a = 6851; //1ac3
                    b = 230433; // 38421
                    c = 412907; // 64CEB
                }
                else
                {
                    // B5F; b:= $A8C3; c:= E9;
                    a = 7007;
                    b = 43203;
                    c = 1001;

                    for (i = 1; i < QIP.Length; )
                    {
                        c = c + (uint)QIP[i];
                        i++;
                    }
                    
                }
                
                for (i = 0; i < hash.Length; )
                {
                    chr = chr + (uint)hash[i];
                    i++;
                }
                Console.WriteLine((char)chr);
                result = result + (char)((byte)(chr ^ (byte)(a >> 8)));
                Console.WriteLine(result);
                a = ((a + chr) * b) + c;

                return result;
        }

Spero nell'aiuto di qualcuno...sono bloccato
aaa
27/10/13 20:47
gigisoft
Controlla l'ultimo coclo for:

Chr:= Ord(hash[i]);


non credo venga tradotto bene con

chr = chr + (uint)hash[i];


e poi, sempre in quel ciclo l'istruzione

i++;


è sicuramente sbagliata (sicuro di conoscere BENE come funziona il ciclo for?)

infine, non conosco il tipo unit del C#, ma in ogni caso, dubito che l'istruzione

Ord(XXXX)

di Delphi venga tradotta bene con un semplice cast di tipo

(unit)XXXX

Ciao. :k:
aaa