Page 1 sur 1

[..] Algorithme de cryptage

Posté : lun. 23 mars 2009 07:11
par ToMac
Bonjour, j'ai un algorithme de cryptage dans plusieurs langages que je ne connais pas donc si quelqu'un connais le C++, PHP, VB, C# ou ActionScript Merci de m'indiquer comment le réaliser en Autoit :

En Vb.Net :

Code : Tout sélectionner

Public Function PassEnc(ByVal pwd As String) As String
        Dim l1, l2, l3, l4, l5 As Integer, l7 As String = "#1"
        Dim hash() As String = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "_"}
        Dim v1, v2 As String
        For l1 = 1 To Len(pwd)
            l2 = Asc(Mid(pwd, l1, 1))
            l3 = Asc(Mid(key, l1, 1))
            l5 = Fix(l2 / 16)
            l4 = l2 Mod 16
            v1 = hash(((l5 + l3) Mod (UBound(hash) + 1)) Mod (UBound(hash) + 1))
            v2 = hash(((l4 + l3) Mod (UBound(hash) + 1)) Mod (UBound(hash) + 1))
            l7 = l7 + v1 + v2
        Next
        Return l7
    End Function

En C# :

Code : Tout sélectionner

public string CryptPassword(string Key, string Password)
        {
            char[] chArray = new char[] { 
                'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 
                'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 
                'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 
                'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_'};
            string str = "#1";
            for (int i = 0; i < Password.Length; i++)
            {
                char ch = Password[i];
                char ch2 = Key[i];
                int num2 = ch / '\x0010';
                int num3 = ch % '\x0010';
                int index = (num2 + ch2) % chArray.Length;
                int num5 = (num3 + ch2) % chArray.Length;
                str = str + chArray[index] + chArray[num5];
            }
            return str;
        }

En Action Script :

Code : Tout sélectionner

cryptPassword = function (pwd, key) {
        var _loc4 = "#1";
        var _loc5 = 0;
        
        while (++_loc5, _loc5 < pwd.length) {
            var _loc6 = pwd.charCodeAt(_loc5);
            var _loc7 = key.charCodeAt(_loc5);
            var _loc8 = Math.floor(_loc6 / 16);
            var _loc9 = _loc6 % 16;
            _loc4 = _loc4 + (ank.utils.Crypt.HASH[(_loc8 + _loc7 % ank.utils.Crypt.HASH.length) % ank.utils.Crypt.HASH.length] + ank.utils.Crypt.HASH[(_loc9 + _loc7 % ank.utils.Crypt.HASH.length) % ank.utils.Crypt.HASH.length]);
        }
        return (_loc4);
    };
    HASH = new Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "_");
}

Et en PHP :

Code : Tout sélectionner

public function crypt_password($_pwd, $_key)
    {      
        $Crypted = "#1";
        $HASH = Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "_");
        
        for($i = 0; $i < strlen($_pwd); $i++)
        {
            $PPass = ord(substr($_pwd,$i,1));
            $PKey = ord(substr($_key,$i,1));
            
            $APass = floor($PPass / 16);
            $AKey = $PPass % 16;
            
            $ANB = ($APass + $PKey) % sizeof($HASH);
            $ANB2 = ($AKey + $PKey) % sizeof($HASH);
            
            $Crypted .= $HASH[$ANB];
            $Crypted .= $HASH[$ANB2];
        }
        return $Crypted;
    }


En C++:

Code : Tout sélectionner

string CryptPassword(string Key, string Password)
{
    char HASH[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
    't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
    'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_'};

    string _Crypted = "#1";

    for(int i = 0; i < Password.length(); i++)
    {
        char PPass = Password[i];

        char PKey = Key[i];

        int APass = (int)PPass / 16;

        int AKey = (int)PPass % 16;

        int ANB = (APass + (int)PKey) % sizeof(HASH);
        int ANB2 = (AKey + (int)PKey) % sizeof(HASH);
        
        _Crypted += HASH[ANB];
        _Crypted += HASH[ANB2];

    }
    return _Crypted;
}

Re: [..] Algorithme de cryptage

Posté : lun. 23 mars 2009 20:37
par timmalos
Ca donnerait quelque chose comme ca:

Code : Tout sélectionner

Func crypt_password($_pwd, $_key)
    Local $Crypted = "#1",$alphabet = "-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",$Crypted = ""
    
    $HASH = StringSplit($alphabet,"")
    
    For $i = 0 to StringLen($_pwd)
            $PKey = asc(StringMid($_key,$i,1))
           
            $APass = floor($PPass / 16)
            $AKey = Mod($PPass,16) 
           
            $ANB = Mod(($APass + $PKey),$HASH[0])
            $ANB2 = Mod(($AKey + $PKey),$HASH[0])
           
            $Crypted &= $HASH[$ANB]
            $Crypted &= $HASH[$ANB2]
        
        
    Next    
    return $Crypted
EndFunc 
 
Y'a un probleme de variable, mais tu as la syntaxe et connaissant ton algorithme tu saura mettre les bonnes variables ;)

Sinon possibilité que tu m'explique ton algorithme?

Re: [..] Algorithme de cryptage

Posté : lun. 23 mars 2009 21:03
par ani

Code : Tout sélectionner

consolewrite(crypt_password("monpass", "macle"))
Exit
Func crypt_password($_pwd, $_key)
    Local $Crypted = "#1",$alphabet = "-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",$Crypted = ""
    
    $HASH = StringSplit($alphabet,"")
    
    For $i = 0 to StringLen($_pwd)
            $PKey = asc(StringMid($_key,$i,1))
            $PPass = asc(StringMid($_pwd,$i,1))

            $APass = floor($PPass / 16)
            $AKey = Mod($PPass,16) 
           
            $ANB = Mod(($APass + $PKey),$HASH[0])
            $ANB2 = Mod(($AKey + $PKey),$HASH[0])
           
            $Crypted &= $HASH[$ANB]
            $Crypted &= $HASH[$ANB2]
        
    Next    
    return $Crypted
EndFunc
Tim t'avais oublié $PPass

Et niveau décrypt ? pas evident là :§

Sinon y a une fonction du nom de StringEncrypt
Ou encore l'algo Crypt
http://www.autoitscript.com/forum/index ... 44581&st=0