[Algo] besoin d'aide

juju hack Messages postés 6 Date d'inscription lundi 23 janvier 2006 Statut Membre Dernière intervention 30 juillet 2008 - 29 juil. 2008 à 13:44
NHenry Messages postés 15112 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 13 avril 2024 - 30 juil. 2008 à 11:03
J'ai trouver un algorithme de cryptage en C# sur internet que j'ai passer
en VB mais là je m'y perds un peut. Donc qi quelqu'un aurais quelque minute
pour m'aider à combler mes erreurs de programmation sa serais simpa :)

Le code VB:

Private Function CryptPassword(ByVal Key As String, ByVal Password As String)
    Dim HASH As 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", "-", "_")
    Dim Crypted As String
    Dim PPass As Char
    Dim PKey As Char
    Dim APass As Integer
    Dim AKey As Integer
    Dim ANB As Integer
    Dim ANB2 As Integer
    Dim i As Integer
    Crypted = "#1"
    For i = 0 To Password.Length - 1
        PPass = Password(i)
        PKey = Key(i)
        APass = CInt(PPass) / 16
        AKey = CInt(PPass) Mod 16
        ANB = (APass + CInt(PKey)) Mod HASH.Length
        ANB2 = (AKey + CInt(PKey)) Mod HASH.Length
        Crypted = HASH(ANB)
        Crypted = HASH(ANB2)
    Next
   Return Crypted
End Function

Le code C#:

publicstring 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) % HASH.Length;

int ANB2 = (AKey + (
int)PKey) % HASH.Length;
_Crypted += HASH[ANB];
_Crypted += HASH[ANB2];
}

return _Crypted;
}

5 réponses

PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
29 juil. 2008 à 14:08
salut,

code obtenu avec http://tools.codes-sources.com/DotNetCodeConverter.aspx

PublicFunction CryptPassword(ByVal Key AsString, ByVal Password AsString) AsString
Dim HASH AsChar() = {"a"C, "b"C, "c"C, "d"C, "e"C, "f"C, _

"g"C, "h"C, "i"C, "j"C, "k"C, "l"C, _

"m"C, "n"C, "o"C, "p"C, "q"C, "r"C, _

"s"C, "t"C, "u"C, "v"C, "w"C, "x"C, _

"y"C, "z"C, "A"C, "B"C, "C"C, "D"C, _

"E"C, "F"C, "G"C, "H"C, "I"C, "J"C, _

"K"C, "L"C, "M"C, "N"C, "O"C, "P"C, _

"Q"C, "R"C, "S"C, "T"C, "U"C, "V"C, _

"W"C, "X"C, "Y"C, "Z"C, "0"C, "1"C, _

"2"C, "3"C, "4"C, "5"C, "6"C, "7"C, _

"8"C, "9"C, "-"C, "_"C}

Dim _Crypted AsString = "#1"

Dim i AsInteger = 0

While i < Password.Length

Dim PPass AsChar = Password(i)

Dim PKey AsChar = Key(i)

Dim APass AsInteger = DirectCast(PPass, Integer) / 16

Dim AKey AsInteger = DirectCast(PPass, Integer) Mod 16

Dim ANB AsInteger = (APass + DirectCast(PKey, Integer)) Mod HASH.Length

Dim ANB2 AsInteger = (AKey + DirectCast(PKey, Integer)) Mod HASH.Length

_Crypted += HASH(ANB)

_Crypted += HASH(ANB2)

System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)

EndWhile
Return _Crypted

EndFunction

<hr size="2" width="100%" />Prenez un instant pour répondre à [infomsg_SONDAGE-POP3-POUR-CS_769706.aspx ce sondage] svp  
0
NHenry Messages postés 15112 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 13 avril 2024 159
29 juil. 2008 à 14:12
Bonjour,

Déjà pour :

Dim HASH As 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", "-",
"_")

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

Ensuite :
For i = 0 To Password.Length - 1
Devient
For i as integer = 0 To Password.Length - 1

Pour le reste, je n'ai pas regardé.

http://nhen0039.chez-alice.fr/index.php
0
juju hack Messages postés 6 Date d'inscription lundi 23 janvier 2006 Statut Membre Dernière intervention 30 juillet 2008
29 juil. 2008 à 19:22
j'ai une erreur il me dit:

Erreur de compilation:
Attendu: Fin d'instruction

sur le ( du char()

je precise sous microsoft viual basic 6

merci de votre aide :)
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
29 juil. 2008 à 19:55
sous VB6 ?....

<li> Vous êtes ici : [infomsg.aspx Thèmes] /[infomsgf_VB-NET-VB-2005_40.aspx VB.NET et VB 2005] / [infomsgt_ALGORITHME_229.aspx Algorithme] / [infomsgt_COMPRESSION-CRYPTAGE_233.aspx Compression & Cryptage] / [http://www.vbfrance.com/infomsg_ALGO-BESOIN-AIDE_1179776.aspx#3 [Algo] besoin d'aide]</li>
sympa !!

pas de classe HASH en VB6, pas plus que de type CHAR

t'es bon pour chercher directement le code en VB6 plutôt que de convertir du C#. tu t'es juste trompé de site dans tes recherches ^^
<hr size="2" width="100%" />Prenez un instant pour répondre à [infomsg_SONDAGE-POP3-POUR-CS_769706.aspx ce sondage] svp  
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
NHenry Messages postés 15112 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 13 avril 2024 159
30 juil. 2008 à 11:03
0
Rejoignez-nous