Cryptage

tomactomac Membre
10:57 modifié dans API AppKit #1
Bonjour,
Dans mon programme j'ai besoin de crypter un mot de passe mais voilà  un ami ma fais l'algorithme en C++ ce qui donne cela :
string CryptPassword(string Key, string Password)<br />{<br />&nbsp; &nbsp; char HASH&#91;] = {&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;, &#39;f&#39;, &#39;g&#39;, &#39;h&#39;, &#39;i&#39;, &#39;j&#39;, &#39;k&#39;, &#39;l&#39;, &#39;m&#39;, &#39;n&#39;, &#39;o&#39;, &#39;p&#39;, &#39;q&#39;, &#39;r&#39;, &#39;s&#39;,<br />&nbsp; &nbsp; &#39;t&#39;, &#39;u&#39;, &#39;v&#39;, &#39;w&#39;, &#39;x&#39;, &#39;y&#39;, &#39;z&#39;, &#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;, &#39;E&#39;, &#39;F&#39;, &#39;G&#39;, &#39;H&#39;, &#39;I&#39;, &#39;J&#39;, &#39;K&#39;, &#39;L&#39;, &#39;M&#39;, &#39;N&#39;, &#39;O&#39;, &#39;P&#39;, &#39;Q&#39;, &#39;R&#39;, &#39;S&#39;, &#39;T&#39;, &#39;U&#39;,<br />&nbsp; &nbsp; &#39;V&#39;, &#39;W&#39;, &#39;X&#39;, &#39;Y&#39;, &#39;Z&#39;, &#39;0&#39;, &#39;1&#39;, &#39;2&#39;, &#39;3&#39;, &#39;4&#39;, &#39;5&#39;, &#39;6&#39;, &#39;7&#39;, &#39;8&#39;, &#39;9&#39;, &#39;-&#39;, &#39;_&#39;};<br /><br />&nbsp; &nbsp; string _Crypted = &quot;#1&quot;;<br /><br />&nbsp; &nbsp; for(int i = 0; i &lt; Password.length(); i++)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; char PPass = Password[i];<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; char PKey = Key[i];<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; int APass = (int)PPass / 16;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; int AKey = (int)PPass % 16;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; int ANB = (APass + (int)PKey) % sizeof(HASH);<br />&nbsp; &nbsp; &nbsp; &nbsp; int ANB2 = (AKey + (int)PKey) % sizeof(HASH);<br />&nbsp; &nbsp; &nbsp;  <br />&nbsp; &nbsp; &nbsp; &nbsp; _Crypted += HASH[ANB];<br />&nbsp; &nbsp; &nbsp; &nbsp; _Crypted += HASH[ANB2];<br /><br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; return _Crypted;<br />}&nbsp;


Et voici comment j'ai essayer de le traduire en Objective-C mais sa provoque une erreur à  chaque fois :
NSString *password = [password initWithString:stringEnter];<br />	NSString *key = [key initWithString:stringKey];<br />	NSArray *hash = [NSArray arrayWithObjects:@&quot;a&quot;, @&quot;b&quot;, @&quot;c&quot;, @&quot;d&quot;, @&quot;e&quot;, &quot;f&quot;, &quot;g&quot;, &quot;h&quot;, &quot;i&quot;, &quot;j&quot;, &quot;k&quot;, &quot;l&quot;, &quot;m&quot;, &quot;n&quot;, &quot;o&quot;, &quot;p&quot;, &quot;q&quot;, &quot;r&quot;, &quot;s&quot;,<br />					 &quot;t&quot;, &quot;u&quot;, &quot;v&quot;, &quot;w&quot;, &quot;x&quot;, &quot;y&quot;, &quot;z&quot;, &quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;, &quot;E&quot;, &quot;F&quot;, &quot;G&quot;, &quot;H&quot;, &quot;I&quot;, &quot;J&quot;, &quot;K&quot;, &quot;L&quot;, &quot;M&quot;, &quot;N&quot;, &quot;O&quot;, &quot;P&quot;, &quot;Q&quot;, &quot;R&quot;, &quot;S&quot;, &quot;T&quot;, &quot;U&quot;,<br />					 &quot;V&quot;, &quot;W&quot;, &quot;X&quot;, &quot;Y&quot;, &quot;Z&quot;, &quot;0&quot;, &quot;1&quot;, &quot;2&quot;, &quot;3&quot;, &quot;4&quot;, &quot;5&quot;, &quot;6&quot;, &quot;7&quot;, &quot;8&quot;, &quot;9&quot;, &quot;-&quot;, &quot;_&quot;];<br />		<br />&nbsp; &nbsp; NSString *crypted = [crypted initWithString:@&quot;#1&quot;];<br />	int longeurPassword = [password length];<br />	int i;<br />&nbsp; &nbsp; for(i = 0; i &lt; longeurPassword; i++)<br />&nbsp; &nbsp; {<br />		<br />&nbsp; &nbsp; &nbsp; &nbsp; char pPass = (@&quot;%@&quot;,[password characterAtIndex: i]);<br />		<br />&nbsp; &nbsp; &nbsp; &nbsp; char pKey = (@&quot;%@&quot;,[key characterAtIndex: i]);<br />		<br />&nbsp; &nbsp; &nbsp; &nbsp; int aPass = (int)pPass / 16;<br />		<br />&nbsp; &nbsp; &nbsp; &nbsp; int aKey = (int)pPass % 16;<br />		<br />&nbsp; &nbsp; &nbsp; &nbsp; int aNB = (aPass + (int)pKey) % sizeof(hash);<br />&nbsp; &nbsp; &nbsp; &nbsp; int aNB2 = (aKey + (int)pKey) % sizeof(hash);<br />		<br />&nbsp; &nbsp; &nbsp; &nbsp; crypted = (@&quot;%@%@&quot;,crypted ,[hash objectAtIndex:aNB]);<br />		crypted = (@&quot;%@%@&quot;,crypted ,[hash objectAtIndex:aNB2]);<br />		<br />&nbsp; &nbsp; }<br />


Voici la description de mes variables :
stringEnter -> correspond au texte entré par l'utilisateur (le mot de passe)
stringKey -> correspond à  la clé de cryptage entré  par l'utilisateur
NSString *crypted = [crypted initWithString:@&quot;#1&quot;];
-> tous les mot de passe une fois crypter commence par "#1"

Voilà  je continue de chercher comment faire marcher cette algorithme mais votre aide me serai utile.
Merci d'avance...

Réponses

  • schlumschlum Membre
    10:57 modifié #2
    ça a l'air assez irréversible son algorithme...
    Si oui, pourquoi ne pas utiliser bêtement un algorithme de "sha1" ?
    Si non, c'est bête de donner l'algo dans un forum public  :P
  • schlumschlum Membre
    10:57 modifié #3
    Sinon, ça sert à  rien de convertir le "HASH" de char [] à  NSArray (à  part pourrir les performances...)
  • schlumschlum Membre
    avril 2009 modifié #4
    (et le code Objective-C est bourré d'erreurs... à  vrai dire, toutes les décrire serait plus long que le programme lui même !)
  • CeetixCeetix Membre
    10:57 modifié #5
    J'avoue c'est pas très malin de donner l'algo de cryptage sur un forum public ^^.
  • schlumschlum Membre
    avril 2009 modifié #6
    Tu peux donner un passe crypté que je voie si je peux trouver le passe ET la clé ?  :)
    C'est une injection d'un groupe 256*256 dans un groupe 64*64, ça devrait donner à  peu près 16 possibilités par caractère, dont beaucoup dans des caractères non imprimables, à  mon avis c'est fortement jouable  :o

    Et pour un peu que tu m'en donnes deux encryptés avec la même clé, là  à  mon avis il tient pas 2 secondes  :P
  • schlumschlum Membre
    avril 2009 modifié #7
    Sinon, avec la clé c'est effectivement réversible en y regardant de plus près...
  • tomactomac Membre
    10:57 modifié #8
    Voici la clé : nzxbvvqouvltppxuleegjxwnqikqdykv
    Le mot de passe : test123
    Le mot de passe crypté : #11Ya__7PM535400

    J'ai corriger mon code mais celui-ci ne marche toujours pas. Si le tient marche pourrais tu me le passer ?
    Merci d'avance
  • schlumschlum Membre
    avril 2009 modifié #9
    NSString *cryptPassword2(NSString *key,NSString *password)<br />{<br />&nbsp; &nbsp; char hash&#91;] = &quot;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_&quot;;<br />&nbsp; &nbsp; const unsigned char *k = (const unsigned char*)[key UTF8String];<br />&nbsp; &nbsp; const unsigned char *p = (const unsigned char*)[password UTF8String];<br />&nbsp; &nbsp; NSMutableString *crypted = [NSMutableString stringWithString:@&quot;#1&quot;];<br />&nbsp; &nbsp; for(;p[0]!=&#39;&#092;0&#39;&amp;&amp;k[0]!=&#39;&#092;0&#39;;++p,++k)<br />&nbsp; &nbsp; &nbsp; &nbsp; [crypted appendFormat:@&quot;%c%c&quot;,hash[(p[0]/16+k[0])%(sizeof(hash)-1)],hash[(p[0]%16+k[0])%(sizeof(hash)-1)]];<br />&nbsp; &nbsp; return [NSString stringWithString:crypted];<br />}
    


    Mais vu la tronche dans le premier message, je suppute que tu as d'énormes soucis avec l'Objective-C... Je ne comprends pas comment tu as pu pondre quelque chose dans lequel tu veux insérer cette fonction.  ???
  • schlumschlum Membre
    10:57 modifié #10
    Version optimisée :
    NSString *cryptPassword(NSString *key,NSString *password)<br />{<br />&nbsp; &nbsp; const char hash&#91;] = &quot;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_&quot;;<br />&nbsp; &nbsp; char rep[1024];<br />&nbsp; &nbsp; const unsigned char *k = (const unsigned char*)[key UTF8String];<br />&nbsp; &nbsp; const unsigned char *p = (const unsigned char*)[password UTF8String];<br />&nbsp; &nbsp; char *r = rep+2;<br />&nbsp; &nbsp; rep[0] = &#39;#&#39;;<br />&nbsp; &nbsp; rep[1] = &#39;1&#39;;<br />&nbsp; &nbsp; for(;p[0]!=&#39;&#092;0&#39;&amp;&amp;k[0]!=&#39;&#092;0&#39;&amp;&amp;r-rep+3&lt;sizeof(rep);++p,++k,r+=2) {<br />&nbsp; &nbsp; &nbsp; &nbsp; r[0] = hash[(p[0]/16+k[0])%(sizeof(hash)-1)];<br />&nbsp; &nbsp; &nbsp; &nbsp; r[1] = hash[(p[0]%16+k[0])%(sizeof(hash)-1)];<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; r[0] = &#39;&#092;0&#39;;<br />&nbsp; &nbsp; return [NSString stringWithUTF8String:rep];<br />}
    
  • schlumschlum Membre
    10:57 modifié #11
    L'analyse de "#11Ya__7PM535400" donne :

    116,46 -&gt; &#39;t&#39;,&#39;.&#39;<br />99,47 -&gt; &#39;c&#39;,&#39;/&#39;<br />82,48 -&gt; &#39;R&#39;,&#39;0&#39;<br />65,49 -&gt; &#39;A&#39;,&#39;1&#39;<br />48,50 -&gt; &#39;0&#39;,&#39;2&#39;<br />116,110 -&gt; &#39;t&#39;,&#39;n&#39;<br />99,111 -&gt; &#39;c&#39;,&#39;o&#39;<br />82,112 -&gt; &#39;R&#39;,&#39;p&#39;<br />65,113 -&gt; &#39;A&#39;,&#39;q&#39;<br />48,114 -&gt; &#39;0&#39;,&#39;r&#39;<br /><br />118,57 -&gt; &#39;v&#39;,&#39;9&#39;<br />101,58 -&gt; &#39;e&#39;,&#39;:&#39;<br />84,59 -&gt; &#39;T&#39;,&#39;;&#39;<br />67,60 -&gt; &#39;C&#39;,&#39;&lt;&#39;<br />50,61 -&gt; &#39;2&#39;,&#39;=&#39;<br />33,62 -&gt; &#39;!&#39;,&#39;&gt;&#39;<br />118,121 -&gt; &#39;v&#39;,&#39;y&#39;<br />101,122 -&gt; &#39;e&#39;,&#39;z&#39;<br />84,123 -&gt; &#39;T&#39;,&#39;{&#39;<br />67,124 -&gt; &#39;C&#39;,&#39;|&#39;<br />50,125 -&gt; &#39;2&#39;,&#39;}&#39;<br />33,126 -&gt; &#39;!&#39;,&#39;~&#39;<br /><br />115,56 -&gt; &#39;s&#39;,&#39;8&#39;<br />98,57 -&gt; &#39;b&#39;,&#39;9&#39;<br />81,58 -&gt; &#39;Q&#39;,&#39;:&#39;<br />64,59 -&gt; &#39;@&#39;,&#39;;&#39;<br />115,120 -&gt; &#39;s&#39;,&#39;x&#39;<br />98,121 -&gt; &#39;b&#39;,&#39;y&#39;<br />81,122 -&gt; &#39;Q&#39;,&#39;z&#39;<br />64,123 -&gt; &#39;@&#39;,&#39;{&#39;<br /><br />116,34 -&gt; &#39;t&#39;,&#39;&quot;&#39;<br />99,35 -&gt; &#39;c&#39;,&#39;#&#39;<br />82,36 -&gt; &#39;R&#39;,&#39;$&#39;<br />65,37 -&gt; &#39;A&#39;,&#39;%&#39;<br />48,38 -&gt; &#39;0&#39;,&#39;&amp;&#39;<br />116,98 -&gt; &#39;t&#39;,&#39;b&#39;<br />99,99 -&gt; &#39;c&#39;,&#39;c&#39;<br />82,100 -&gt; &#39;R&#39;,&#39;d&#39;<br />65,101 -&gt; &#39;A&#39;,&#39;e&#39;<br />48,102 -&gt; &#39;0&#39;,&#39;f&#39;<br /><br />117,50 -&gt; &#39;u&#39;,&#39;2&#39;<br />100,51 -&gt; &#39;d&#39;,&#39;3&#39;<br />83,52 -&gt; &#39;S&#39;,&#39;4&#39;<br />66,53 -&gt; &#39;B&#39;,&#39;5&#39;<br />49,54 -&gt; &#39;1&#39;,&#39;6&#39;<br />32,55 -&gt; &#39; &#39;,&#39;7&#39;<br />117,114 -&gt; &#39;u&#39;,&#39;r&#39;<br />100,115 -&gt; &#39;d&#39;,&#39;s&#39;<br />83,116 -&gt; &#39;S&#39;,&#39;t&#39;<br />66,117 -&gt; &#39;B&#39;,&#39;u&#39;<br />49,118 -&gt; &#39;1&#39;,&#39;v&#39;<br />32,119 -&gt; &#39; &#39;,&#39;w&#39;<br /><br />118,50 -&gt; &#39;v&#39;,&#39;2&#39;<br />101,51 -&gt; &#39;e&#39;,&#39;3&#39;<br />84,52 -&gt; &#39;T&#39;,&#39;4&#39;<br />67,53 -&gt; &#39;C&#39;,&#39;5&#39;<br />50,54 -&gt; &#39;2&#39;,&#39;6&#39;<br />33,55 -&gt; &#39;!&#39;,&#39;7&#39;<br />118,114 -&gt; &#39;v&#39;,&#39;r&#39;<br />101,115 -&gt; &#39;e&#39;,&#39;s&#39;<br />84,116 -&gt; &#39;T&#39;,&#39;t&#39;<br />67,117 -&gt; &#39;C&#39;,&#39;u&#39;<br />50,118 -&gt; &#39;2&#39;,&#39;v&#39;<br />33,119 -&gt; &#39;!&#39;,&#39;w&#39;<br /><br />119,45 -&gt; &#39;w&#39;,&#39;-&#39;<br />102,46 -&gt; &#39;f&#39;,&#39;.&#39;<br />85,47 -&gt; &#39;U&#39;,&#39;/&#39;<br />68,48 -&gt; &#39;D&#39;,&#39;0&#39;<br />51,49 -&gt; &#39;3&#39;,&#39;1&#39;<br />34,50 -&gt; &#39;&quot;&#39;,&#39;2&#39;<br />119,109 -&gt; &#39;w&#39;,&#39;m&#39;<br />102,110 -&gt; &#39;f&#39;,&#39;n&#39;<br />85,111 -&gt; &#39;U&#39;,&#39;o&#39;<br />68,112 -&gt; &#39;D&#39;,&#39;p&#39;<br />51,113 -&gt; &#39;3&#39;,&#39;q&#39;<br />34,114 -&gt; &#39;&quot;&#39;,&#39;r&#39;
    


    [tcRA0][veTC2!][sbQ@][tcRA0][udSB1][ceTC2!][wfUD3&quot;]
    


    Soit en brut force, seulement 108000 possibilités...
    Et avec un peu d'instinct, ça se trouve.
  • tomactomac Membre
    10:57 modifié #12
    Merci beaucoup mon problème est résolu.  :adios!: :adios!: 
Connectez-vous ou Inscrivez-vous pour répondre.