Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1473 connectés 

  FORUM HardWare.fr
  Programmation

  fonction de hashage, Aie !

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

fonction de hashage, Aie !

n°64710
barbarella
Posté le 12-10-2001 à 10:00:09  profilanswer
 

salut la foule,
 
bon je teste actuellement des fonctions hashages pour tenter de remplacer ma fonc de recherche dicho (sur liste de 7000 mots  environ). C'est pas terrible terrible, 30 a 40% d'echec :(
 
Vous avez des idées de truc qui marche bien. J'ai pas trop de prob avec la théorie des nombres donc même complexe je prends.
 
merci

mood
Publicité
Posté le 12-10-2001 à 10:00:09  profilanswer
 

n°64716
Requin
Posté le 12-10-2001 à 10:14:48  profilanswer
 

MD5 n'irait pas ?
 
Le code source original en C est dispo sur le net... tu trouveras aussi de nombreuses implémentations dans d'autres langages.

n°64719
barbarella
Posté le 12-10-2001 à 10:31:52  profilanswer
 

si quelqu'un avait une adresse directe pour l'algo du MD5 (sous forme athématique de pref) ça serait sympa, parceque des site qui citent le M5 il y en a une tonne, mais des qui donne l'algo pas de bcp apparement.
 
requin : merci pour le conseil :)

n°64721
barbarella
Posté le 12-10-2001 à 10:43:07  profilanswer
 

requin,
 
bon apparement le prob avec le MD5 est qu'il retourne une valeur sur 128 bits. je me vois mal faire un tableau de de 2^128 elem :D
 
enfin ça c'est pour sa verison cryptographique, il existerait apparrment une version pour le hashage (a vérifier).
 
des idées MD5 ou autre.

 

[edtdd]--Message édité par Barbarella--[/edtdd]

n°64723
Requin
Posté le 12-10-2001 à 10:47:29  profilanswer
 

MD5 fait l'opbjet du RFC 1321 dont voici le contenu et aux dernières nouvelles c'est une focntion de hashage qui est sûre :
 

Code :
  1. Network Working Group                                          R. Rivest
  2. Request for Comments: 1321           MIT Laboratory for Computer Science
  3.                                              and RSA Data Security, Inc.
  4.                                                               April 1992
  5.                      The MD5 Message-Digest Algorithm
  6. Status of this Memo
  7.    This memo provides information for the Internet community.  It does
  8.    not specify an Internet standard.  Distribution of this memo is
  9.    unlimited.
  10. Acknowlegements
  11.    We would like to thank Don Coppersmith, Burt Kaliski, Ralph Merkle,
  12.    David Chaum, and Noam Nisan for numerous helpful comments and
  13.    suggestions.
  14. Table of Contents
  15.    1. Executive Summary                                                1
  16.    2. Terminology and Notation                                         2
  17.    3. MD5 Algorithm Description                                        3
  18.    4. Summary                                                          6
  19.    5. Differences Between MD4 and MD5                                  6
  20.    References                                                          7
  21.    APPENDIX A - Reference Implementation                               7
  22.    Security Considerations                                            21
  23.    Author's Address                                                   21
  24. 1. Executive Summary
  25.    This document describes the MD5 message-digest algorithm. The
  26.    algorithm takes as input a message of arbitrary length and produces
  27.    as output a 128-bit "fingerprint" or "message digest" of the input.
  28.    It is conjectured that it is computationally infeasible to produce
  29.    two messages having the same message digest, or to produce any
  30.    message having a given prespecified target message digest. The MD5
  31.    algorithm is intended for digital signature applications, where a
  32.    large file must be "compressed" in a secure manner before being
  33.    encrypted with a private (secret) key under a public-key cryptosystem
  34.    such as RSA.
  35. Rivest                                                          [Page 1]
  36. RFC 1321              MD5 Message-Digest Algorithm            April 1992
  37.    The MD5 algorithm is designed to be quite fast on 32-bit machines. In
  38.    addition, the MD5 algorithm does not require any large substitution
  39.    tables; the algorithm can be coded quite compactly.
  40.    The MD5 algorithm is an extension of the MD4 message-digest algorithm
  41.    1,2]. MD5 is slightly slower than MD4, but is more "conservative" in
  42.    design. MD5 was designed because it was felt that MD4 was perhaps
  43.    being adopted for use more quickly than justified by the existing
  44.    critical review; because MD4 was designed to be exceptionally fast,
  45.    it is "at the edge" in terms of risking successful cryptanalytic
  46.    attack. MD5 backs off a bit, giving up a little in speed for a much
  47.    greater likelihood of ultimate security. It incorporates some
  48.    suggestions made by various reviewers, and contains additional
  49.    optimizations. The MD5 algorithm is being placed in the public domain
  50.    for review and possible adoption as a standard.
  51.    For OSI-based applications, MD5's object identifier is
  52.    md5 OBJECT IDENTIFIER ::=
  53.      iso(1) member-body(2) US(840) rsadsi(113549) digestAlgorithm(2) 5}
  54.    In the X.509 type AlgorithmIdentifier [3], the parameters for MD5
  55.    should have type NULL.
  56. 2. Terminology and Notation
  57.    In this document a "word" is a 32-bit quantity and a "byte" is an
  58.    eight-bit quantity. A sequence of bits can be interpreted in a
  59.    natural manner as a sequence of bytes, where each consecutive group
  60.    of eight bits is interpreted as a byte with the high-order (most
  61.    significant) bit of each byte listed first. Similarly, a sequence of
  62.    bytes can be interpreted as a sequence of 32-bit words, where each
  63.    consecutive group of four bytes is interpreted as a word with the
  64.    low-order (least significant) byte given first.
  65.    Let x_i denote "x sub i". If the subscript is an expression, we
  66.    surround it in braces, as in x_{i+1}. Similarly, we use ^ for
  67.    superscripts (exponentiation), so that x^i denotes x to the i-th
  68.    power.
  69.    Let the symbol "+" denote addition of words (i.e., modulo-2^32
  70.    addition). Let X <<< s denote the 32-bit value obtained by circularly
  71.    shifting (rotating) X left by s bit positions. Let not(X) denote the
  72.    bit-wise complement of X, and let X v Y denote the bit-wise OR of X
  73.    and Y. Let X xor Y denote the bit-wise XOR of X and Y, and let XY
  74.    denote the bit-wise AND of X and Y.
  75. Rivest                                                          [Page 2]
  76. RFC 1321              MD5 Message-Digest Algorithm            April 1992
  77. 3. MD5 Algorithm Description
  78.    We begin by supposing that we have a b-bit message as input, and that
  79.    we wish to find its message digest. Here b is an arbitrary
  80.    nonnegative integer; b may be zero, it need not be a multiple of
  81.    eight, and it may be arbitrarily large. We imagine the bits of the
  82.    message written down as follows:
  83.           m_0 m_1 ... m_{b-1}
  84.    The following five steps are performed to compute the message digest
  85.    of the message.
  86. 3.1 Step 1. Append Padding Bits
  87.    The message is "padded" (extended) so that its length (in bits) is
  88.    congruent to 448, modulo 512. That is, the message is extended so
  89.    that it is just 64 bits shy of being a multiple of 512 bits long.
  90.    Padding is always performed, even if the length of the message is
  91.    already congruent to 448, modulo 512.
  92.    Padding is performed as follows: a single "1" bit is appended to the
  93.    message, and then "0" bits are appended so that the length in bits of
  94.    the padded message becomes congruent to 448, modulo 512. In all, at
  95.    least one bit and at most 512 bits are appended.
  96. 3.2 Step 2. Append Length
  97.    A 64-bit representation of b (the length of the message before the
  98.    padding bits were added) is appended to the result of the previous
  99.    step. In the unlikely event that b is greater than 2^64, then only
  100.    the low-order 64 bits of b are used. (These bits are appended as two
  101.    32-bit words and appended low-order word first in accordance with the
  102.    previous conventions.)
  103.    At this point the resulting message (after padding with bits and with
  104.    b) has a length that is an exact multiple of 512 bits. Equivalently,
  105.    this message has a length that is an exact multiple of 16 (32-bit)
  106.    words. Let M[0 ... N-1] denote the words of the resulting message,
  107.    where N is a multiple of 16.
  108. 3.3 Step 3. Initialize MD Buffer
  109.    A four-word buffer (A,B,C,D) is used to compute the message digest.
  110.    Here each of A, B, C, D is a 32-bit register. These registers are
  111.    initialized to the following values in hexadecimal, low-order bytes
  112.    first):
  113. Rivest                                                          [Page 3]
  114. RFC 1321              MD5 Message-Digest Algorithm            April 1992
  115.           word A: 01 23 45 67
  116.           word B: 89 ab cd ef
  117.           word C: fe dc ba 98
  118.           word D: 76 54 32 10
  119. 3.4 Step 4. Process Message in 16-Word Blocks
  120.    We first define four auxiliary functions that each take as input
  121.    three 32-bit words and produce as output one 32-bit word.
  122.           F(X,Y,Z) = XY v not(X) Z
  123.           G(X,Y,Z) = XZ v Y not(Z)
  124.           H(X,Y,Z) = X xor Y xor Z
  125.           I(X,Y,Z) = Y xor (X v not(Z))
  126.    In each bit position F acts as a conditional: if X then Y else Z.
  127.    The function F could have been defined using + instead of v since XY
  128.    and not(X)Z will never have 1's in the same bit position.) It is
  129.    interesting to note that if the bits of X, Y, and Z are independent
  130.    and unbiased, the each bit of F(X,Y,Z) will be independent and
  131.    unbiased.
  132.    The functions G, H, and I are similar to the function F, in that they
  133.    act in "bitwise parallel" to produce their output from the bits of X,
  134.    Y, and Z, in such a manner that if the corresponding bits of X, Y,
  135.    and Z are independent and unbiased, then each bit of G(X,Y,Z),
  136.    H(X,Y,Z), and I(X,Y,Z) will be independent and unbiased. Note that
  137.    the function H is the bit-wise "xor" or "parity" function of its
  138.    inputs.
  139.    This step uses a 64-element table T[1 ... 64] constructed from the
  140.    sine function. Let T[i] denote the i-th element of the table, which
  141.    is equal to the integer part of 4294967296 times abs(sin(i)), where i
  142.    is in radians. The elements of the table are given in the appendix.
  143.    Do the following:
  144.    /* Process each 16-word block. */
  145.    For i = 0 to N/16-1 do
  146.      /* Copy block i into X. */
  147.      For j = 0 to 15 do
  148.        Set X[j] to M[i*16+j].
  149.      end /* of loop on j */
  150.      /* Save A as AA, B as BB, C as CC, and D as DD. */
  151.      AA = A
  152.      BB = B
  153. Rivest                                                          [Page 4]
  154. RFC 1321              MD5 Message-Digest Algorithm            April 1992
  155.      CC = C
  156.      DD = D
  157.      /* Round 1. */
  158.      /* Let [abcd k s i] denote the operation
  159.           a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */
  160.      /* Do the following 16 operations. */
  161.      [ABCD  0  7  1]  [DABC  1 12  2]  [CDAB  2 17  3]  [BCDA  3 22  4]
  162.      [ABCD  4  7  5]  [DABC  5 12  6]  [CDAB  6 17  7]  [BCDA  7 22  8]
  163.      [ABCD  8  7  9]  [DABC  9 12 10]  [CDAB 10 17 11]  [BCDA 11 22 12]
  164.      [ABCD 12  7 13]  [DABC 13 12 14]  [CDAB 14 17 15]  [BCDA 15 22 16]
  165.      /* Round 2. */
  166.      /* Let [abcd k s i] denote the operation
  167.           a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */
  168.      /* Do the following 16 operations. */
  169.      [ABCD  1  5 17]  [DABC  6  9 18]  [CDAB 11 14 19]  [BCDA  0 20 20]
  170.      [ABCD  5  5 21]  [DABC 10  9 22]  [CDAB 15 14 23]  [BCDA  4 20 24]
  171.      [ABCD  9  5 25]  [DABC 14  9 26]  [CDAB  3 14 27]  [BCDA  8 20 28]
  172.      [ABCD 13  5 29]  [DABC  2  9 30]  [CDAB  7 14 31]  [BCDA 12 20 32]
  173.      /* Round 3. */
  174.      /* Let [abcd k s t] denote the operation
  175.           a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */
  176.      /* Do the following 16 operations. */
  177.      [ABCD  5  4 33]  [DABC  8 11 34]  [CDAB 11 16 35]  [BCDA 14 23 36]
  178.      [ABCD  1  4 37]  [DABC  4 11 38]  [CDAB  7 16 39]  [BCDA 10 23 40]
  179.      [ABCD 13  4 41]  [DABC  0 11 42]  [CDAB  3 16 43]  [BCDA  6 23 44]
  180.      [ABCD  9  4 45]  [DABC 12 11 46]  [CDAB 15 16 47]  [BCDA  2 23 48]
  181.      /* Round 4. */
  182.      /* Let [abcd k s t] denote the operation
  183.           a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */
  184.      /* Do the following 16 operations. */
  185.      [ABCD  0  6 49]  [DABC  7 10 50]  [CDAB 14 15 51]  [BCDA  5 21 52]
  186.      [ABCD 12  6 53]  [DABC  3 10 54]  [CDAB 10 15 55]  [BCDA  1 21 56]
  187.      [ABCD  8  6 57]  [DABC 15 10 58]  [CDAB  6 15 59]  [BCDA 13 21 60]
  188.      [ABCD  4  6 61]  [DABC 11 10 62]  [CDAB  2 15 63]  [BCDA  9 21 64]
  189.      /* Then perform the following additions. (That is increment each
  190.         of the four registers by the value it had before this block
  191.         was started.) */
  192.      A = A + AA
  193.      B = B + BB
  194.      C = C + CC
  195.      D = D + DD
  196.    end /* of loop on i */
  197. Rivest                                                          [Page 5]
  198. RFC 1321              MD5 Message-Digest Algorithm            April 1992
  199. 3.5 Step 5. Output
  200.    The message digest produced as output is A, B, C, D. That is, we
  201.    begin with the low-order byte of A, and end with the high-order byte
  202.    of D.
  203.    This completes the description of MD5. A reference implementation in
  204.    C is given in the appendix.
  205. 4. Summary
  206.    The MD5 message-digest algorithm is simple to implement, and provides
  207.    a "fingerprint" or message digest of a message of arbitrary length.
  208.    It is conjectured that the difficulty of coming up with two messages
  209.    having the same message digest is on the order of 2^64 operations,
  210.    and that the difficulty of coming up with any message having a given
  211.    message digest is on the order of 2^128 operations. The MD5 algorithm
  212.    has been carefully scrutinized for weaknesses. It is, however, a
  213.    relatively new algorithm and further security analysis is of course
  214.    justified, as is the case with any new proposal of this sort.
  215. 5. Differences Between MD4 and MD5
  216.      The following are the differences between MD4 and MD5:
  217.        1.   A fourth round has been added.
  218.        2.   Each step now has a unique additive constant.
  219.        3.   The function g in round 2 was changed from (XY v XZ v YZ) to
  220.        (XZ v Y not(Z)) to make g less symmetric.
  221.        4.   Each step now adds in the result of the previous step.  This
  222.        promotes a faster "avalanche effect".
  223.        5.   The order in which input words are accessed in rounds 2 and
  224.        3 is changed, to make these patterns less like each other.
  225.        6.   The shift amounts in each round have been approximately
  226.        optimized, to yield a faster "avalanche effect." The shifts in
  227.        different rounds are distinct.
  228. Rivest                                                          [Page 6]
  229. RFC 1321              MD5 Message-Digest Algorithm            April 1992
  230. References
  231.    [1] Rivest, R., "The MD4 Message Digest Algorithm", RFC 1320, MIT and
  232.        RSA Data Security, Inc., April 1992.
  233.    [2] Rivest, R., "The MD4 message digest algorithm", in A.J.  Menezes
  234.        and S.A. Vanstone, editors, Advances in Cryptology - CRYPTO '90
  235.        Proceedings, pages 303-311, Springer-Verlag, 1991.
  236.    [3] CCITT Recommendation X.509 (1988), "The Directory -
  237.        Authentication Framework."
  238. APPENDIX A - Reference Implementation
  239.    This appendix contains the following files taken from RSAREF: A
  240.    Cryptographic Toolkit for Privacy-Enhanced Mail:
  241.      global.h -- global header file
  242.      md5.h -- header file for MD5
  243.      md5c.c -- source code for MD5
  244.    For more information on RSAREF, send email to <rsaref@rsa.com>.
  245.    The appendix also includes the following file:
  246.      mddriver.c -- test driver for MD2, MD4 and MD5
  247.    The driver compiles for MD5 by default but can compile for MD2 or MD4
  248.    if the symbol MD is defined on the C compiler command line as 2 or 4.
  249.    The implementation is portable and should work on many different
  250.    plaforms. However, it is not difficult to optimize the implementation
  251.    on particular platforms, an exercise left to the reader. For example,
  252.    on "little-endian" platforms where the lowest-addressed byte in a 32-
  253.    bit word is the least significant and there are no alignment
  254.    restrictions, the call to Decode in MD5Transform can be replaced with
  255.    a typecast.
  256. A.1 global.h
  257. /* GLOBAL.H - RSAREF types and constants
  258. */
  259. /* PROTOTYPES should be set to one if and only if the compiler supports
  260.   function argument prototyping.
  261. The following makes PROTOTYPES default to 0 if it has not already
  262. Rivest                                                          [Page 7]
  263.  
  264. RFC 1321              MD5 Message-Digest Algorithm            April 1992
  265.   been defined with C compiler flags.
  266. */
  267. #ifndef PROTOTYPES
  268. #define PROTOTYPES 0
  269. #endif
  270. /* POINTER defines a generic pointer type */
  271. typedef unsigned char *POINTER;
  272. /* UINT2 defines a two byte word */
  273. typedef unsigned short int UINT2;
  274. /* UINT4 defines a four byte word */
  275. typedef unsigned long int UINT4;
  276. /* PROTO_LIST is defined depending on how PROTOTYPES is defined above.
  277. If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
  278.   returns an empty list.
  279. */
  280. #if PROTOTYPES
  281. #define PROTO_LIST(list) list
  282. #else
  283. #define PROTO_LIST(list) ()
  284. #endif
  285. A.2 md5.h
  286. /* MD5.H - header file for MD5C.C
  287. */
  288. /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
  289. rights reserved.
  290. License to copy and use this software is granted provided that it
  291. is identified as the "RSA Data Security, Inc. MD5 Message-Digest
  292. Algorithm" in all material mentioning or referencing this software
  293. or this function.
  294. License is also granted to make and use derivative works provided
  295. that such works are identified as "derived from the RSA Data
  296. Security, Inc. MD5 Message-Digest Algorithm" in all material
  297. mentioning or referencing the derived work.
  298. RSA Data Security, Inc. makes no representations concerning either
  299. the merchantability of this software or the suitability of this
  300. software for any particular purpose. It is provided "as is"
  301. without express or implied warranty of any kind.
  302. Rivest                                                          [Page 8]
  303.  
  304. RFC 1321              MD5 Message-Digest Algorithm            April 1992
  305. These notices must be retained in any copies of any part of this
  306. documentation and/or software.
  307. */
  308. /* MD5 context. */
  309. typedef struct {
  310.   UINT4 state[4];                                   /* state (ABCD) */
  311.   UINT4 count[2];        /* number of bits, modulo 2^64 (lsb first) */
  312.   unsigned char buffer[64];                         /* input buffer */
  313. } MD5_CTX;
  314. void MD5Init PROTO_LIST ((MD5_CTX *));
  315. void MD5Update PROTO_LIST
  316.   ((MD5_CTX *, unsigned char *, unsigned int));
  317. void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *));
  318. A.3 md5c.c
  319. /* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
  320. */
  321. /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
  322. rights reserved.
  323. License to copy and use this software is granted provided that it
  324. is identified as the "RSA Data Security, Inc. MD5 Message-Digest
  325. Algorithm" in all material mentioning or referencing this software
  326. or this function.
  327. License is also granted to make and use derivative works provided
  328. that such works are identified as "derived from the RSA Data
  329. Security, Inc. MD5 Message-Digest Algorithm" in all material
  330. mentioning or referencing the derived work.
  331. RSA Data Security, Inc. makes no representations concerning either
  332. the merchantability of this software or the suitability of this
  333. software for any particular purpose. It is provided "as is"
  334. without express or implied warranty of any kind.
  335. These notices must be retained in any copies of any part of this
  336. documentation and/or software.
  337. */
  338. #include "global.h"
  339. #include "md5.h"
  340. /* Constants for MD5Transform routine.
  341. */
  342. Rivest                                                          [Page 9]
  343. RFC 1321              MD5 Message-Digest Algorithm            April 1992
  344. #define S11 7
  345. #define S12 12
  346. #define S13 17
  347. #define S14 22
  348. #define S21 5
  349. #define S22 9
  350. #define S23 14
  351. #define S24 20
  352. #define S31 4
  353. #define S32 11
  354. #define S33 16
  355. #define S34 23
  356. #define S41 6
  357. #define S42 10
  358. #define S43 15
  359. #define S44 21
  360. static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
  361. static void Encode PROTO_LIST
  362.   ((unsigned char *, UINT4 *, unsigned int));
  363. static void Decode PROTO_LIST
  364.   ((UINT4 *, unsigned char *, unsigned int));
  365. static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
  366. static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
  367. static unsigned char PADDING[64] = {
  368.   0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  369.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  370.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  371. };
  372. /* F, G, H and I are basic MD5 functions.
  373. */
  374. #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
  375. #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
  376. #define H(x, y, z) ((x) ^ (y) ^ (z))
  377. #define I(x, y, z) ((y) ^ ((x) | (~z)))
  378. /* ROTATE_LEFT rotates x left n bits.
  379. */
  380. #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
  381. /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
  382. Rotation is separate from addition to prevent recomputation.
  383. */
  384. #define FF(a, b, c, d, x, s, ac) { \
  385. (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
  386. (a) = ROTATE_LEFT ((a), (s)); \
  387. Rivest                                                         [Page 10]
  388. RFC 1321              MD5 Message-Digest Algorithm            April 1992
  389. (a) += (b); \
  390.   }
  391. #define GG(a, b, c, d, x, s, ac) { \
  392. (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
  393. (a) = ROTATE_LEFT ((a), (s)); \
  394. (a) += (b); \
  395.   }
  396. #define HH(a, b, c, d, x, s, ac) { \
  397. (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
  398. (a) = ROTATE_LEFT ((a), (s)); \
  399. (a) += (b); \
  400.   }
  401. #define II(a, b, c, d, x, s, ac) { \
  402. (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
  403. (a) = ROTATE_LEFT ((a), (s)); \
  404. (a) += (b); \
  405.   }
  406. /* MD5 initialization. Begins an MD5 operation, writing a new context.
  407. */
  408. void MD5Init (context)
  409. MD5_CTX *context;                                        /* context */
  410. {
  411.   context->count[0] = context->count[1] = 0;
  412.   /* Load magic initialization constants.
  413. */
  414.   context->state[0] = 0x67452301;
  415.   context->state[1] = 0xefcdab89;
  416.   context->state[2] = 0x98badcfe;
  417.   context->state[3] = 0x10325476;
  418. }
  419. /* MD5 block update operation. Continues an MD5 message-digest
  420.   operation, processing another message block, and updating the
  421.   context.
  422. */
  423. void MD5Update (context, input, inputLen)
  424. MD5_CTX *context;                                        /* context */
  425. unsigned char *input;                                /* input block */
  426. unsigned int inputLen;                     /* length of input block */
  427. {
  428.   unsigned int i, index, partLen;
  429.   /* Compute number of bytes mod 64 */
  430.   index = (unsigned int)((context->count[0] >> 3) & 0x3F);
  431.   /* Update number of bits */
  432.   if ((context->count[0] += ((UINT4)inputLen << 3))
  433. Rivest                                                         [Page 11]
  434. RFC 1321              MD5 Message-Digest Algorithm            April 1992
  435.    < ((UINT4)inputLen << 3))
  436. context->count[1]++;
  437.   context->count[1] += ((UINT4)inputLen >> 29);
  438.   partLen = 64 - index;
  439.   /* Transform as many times as possible.
  440. */
  441.   if (inputLen >= partLen) {
  442. MD5_memcpy
  443.    ((POINTER)&context->buffer[index], (POINTER)input, partLen);
  444. MD5Transform (context->state, context->buffer);
  445. for (i = partLen; i + 63 < inputLen; i += 64)
  446.    MD5Transform (context->state, &input[i]);
  447. index = 0;
  448.   }
  449.   else
  450. i = 0;
  451.   /* Buffer remaining input */
  452.   MD5_memcpy
  453. ((POINTER)&context->buffer[index], (POINTER)&input[i],
  454.   inputLen-i);
  455. }
  456. /* MD5 finalization. Ends an MD5 message-digest operation, writing the
  457.   the message digest and zeroizing the context.
  458. */
  459. void MD5Final (digest, context)
  460. unsigned char digest[16];                         /* message digest */
  461. MD5_CTX *context;                                       /* context */
  462. {
  463.   unsigned char bits[8];
  464.   unsigned int index, padLen;
  465.   /* Save number of bits */
  466.   Encode (bits, context->count, 8);
  467.   /* Pad out to 56 mod 64.
  468. */
  469.   index = (unsigned int)((context->count[0] >> 3) & 0x3f);
  470.   padLen = (index < 56) ? (56 - index) : (120 - index);
  471.   MD5Update (context, PADDING, padLen);
  472.   /* Append length (before padding) */
  473.   MD5Update (context, bits, 8);
  474. Rivest                                                         [Page 12]
  475. RFC 1321              MD5 Message-Digest Algorithm            April 1992
  476.   /* Store state in digest */
  477.   Encode (digest, context->state, 16);
  478.   /* Zeroize sensitive information.
  479. */
  480.   MD5_memset ((POINTER)context, 0, sizeof (*context));
  481. }
  482. /* MD5 basic transformation. Transforms state based on block.
  483. */
  484. static void MD5Transform (state, block)
  485. UINT4 state[4];
  486. unsigned char block[64];
  487. {
  488.   UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
  489.   Decode (x, block, 64);
  490.   /* Round 1 */
  491.   FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
  492.   FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
  493.   FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
  494.   FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
  495.   FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
  496.   FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
  497.   FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
  498.   FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
  499.   FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
  500.   FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
  501.   FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
  502.   FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
  503.   FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
  504.   FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
  505.   FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
  506.   FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
  507. /* Round 2 */
  508.   GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
  509.   GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
  510.   GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
  511.   GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
  512.   GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
  513.   GG (d, a, b, c, x[10], S22,  0x2441453); /* 22 */
  514.   GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
  515.   GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
  516.   GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
  517.   GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
  518.   GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
  519. Rivest                                                         [Page 13]
  520. RFC 1321              MD5 Message-Digest Algorithm            April 1992
  521.   GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
  522.   GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
  523.   GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
  524.   GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
  525.   GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
  526.   /* Round 3 */
  527.   HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
  528.   HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
  529.   HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
  530.   HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
  531.   HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
  532.   HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
  533.   HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
  534.   HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
  535.   HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
  536.   HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
  537.   HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
  538.   HH (b, c, d, a, x[ 6], S34,  0x4881d05); /* 44 */
  539.   HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
  540.   HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
  541.   HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
  542.   HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
  543.   /* Round 4 */
  544.   II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
  545.   II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
  546.   II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
  547.   II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
  548.   II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
  549.   II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
  550.   II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
  551.   II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
  552.   II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
  553.   II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
  554.   II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
  555.   II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
  556.   II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
  557.   II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
  558.   II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
  559.   II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
  560.   state[0] += a;
  561.   state[1] += b;
  562.   state[2] += c;
  563.   state[3] += d;
  564.   /* Zeroize sensitive information.
  565. Rivest                                                         [Page 14]
  566.  
  567. RFC 1321              MD5 Message-Digest Algorithm            April 1992
  568. */
  569.   MD5_memset ((POINTER)x, 0, sizeof (x));
  570. }
  571. /* Encodes input (UINT4) into output (unsigned char). Assumes len is
  572.   a multiple of 4.
  573. */
  574. static void Encode (output, input, len)
  575. unsigned char *output;
  576. UINT4 *input;
  577. unsigned int len;
  578. {
  579.   unsigned int i, j;
  580.   for (i = 0, j = 0; j < len; i++, j += 4) {
  581. output[j] = (unsigned char)(input[i] & 0xff);
  582. output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
  583. output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
  584. output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
  585.   }
  586. }
  587. /* Decodes input (unsigned char) into output (UINT4). Assumes len is
  588.   a multiple of 4.
  589. */
  590. static void Decode (output, input, len)
  591. UINT4 *output;
  592. unsigned char *input;
  593. unsigned int len;
  594. {
  595.   unsigned int i, j;
  596.   for (i = 0, j = 0; j < len; i++, j += 4)
  597. output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
  598.    (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
  599. }
  600. /* Note: Replace "for loop" with standard memcpy if possible.
  601. */
  602. static void MD5_memcpy (output, input, len)
  603. POINTER output;
  604. POINTER input;
  605. unsigned int len;
  606. {
  607.   unsigned int i;
  608.   for (i = 0; i < len; i++)
  609. Rivest                                                         [Page 15]
  610. RFC 1321              MD5 Message-Digest Algorithm            April 1992
  611. output[i] = input[i];
  612. }
  613. /* Note: Replace "for loop" with standard memset if possible.
  614. */
  615. static void MD5_memset (output, value, len)
  616. POINTER output;
  617. int value;
  618. unsigned int len;
  619. {
  620.   unsigned int i;
  621.   for (i = 0; i < len; i++)
  622. ((char *)output)[i] = (char)value;
  623. }
  624. A.4 mddriver.c
  625. /* MDDRIVER.C - test driver for MD2, MD4 and MD5
  626. */
  627. /* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
  628. rights reserved.
  629. RSA Data Security, Inc. makes no representations concerning either
  630. the merchantability of this software or the suitability of this
  631. software for any particular purpose. It is provided "as is"
  632. without express or implied warranty of any kind.
  633. These notices must be retained in any copies of any part of this
  634. documentation and/or software.
  635. */
  636. /* The following makes MD default to MD5 if it has not already been
  637.   defined with C compiler flags.
  638. */
  639. #ifndef MD
  640. #define MD MD5
  641. #endif
  642. #include <stdio.h>
  643. #include <time.h>
  644. #include <string.h>
  645. #include "global.h"
  646. #if MD == 2
  647. #include "md2.h"
  648. #endif
  649. #if MD == 4
  650. Rivest                                                         [Page 16]
  651. RFC 1321              MD5 Message-Digest Algorithm            April 1992
  652. #include "md4.h"
  653. #endif
  654. #if MD == 5
  655. #include "md5.h"
  656. #endif
  657. /* Length of test block, number of test blocks.
  658. */
  659. #define TEST_BLOCK_LEN 1000
  660. #define TEST_BLOCK_COUNT 1000
  661. static void MDString PROTO_LIST ((char *));
  662. static void MDTimeTrial PROTO_LIST ((void));
  663. static void MDTestSuite PROTO_LIST ((void));
  664. static void MDFile PROTO_LIST ((char *));
  665. static void MDFilter PROTO_LIST ((void));
  666. static void MDPrint PROTO_LIST ((unsigned char [16]));
  667. #if MD == 2
  668. #define MD_CTX MD2_CTX
  669. #define MDInit MD2Init
  670. #define MDUpdate MD2Update
  671. #define MDFinal MD2Final
  672. #endif
  673. #if MD == 4
  674. #define MD_CTX MD4_CTX
  675. #define MDInit MD4Init
  676. #define MDUpdate MD4Update
  677. #define MDFinal MD4Final
  678. #endif
  679. #if MD == 5
  680. #define MD_CTX MD5_CTX
  681. #define MDInit MD5Init
  682. #define MDUpdate MD5Update
  683. #define MDFinal MD5Final
  684. #endif
  685. /* Main driver.
  686. Arguments (may be any combination):
  687.   -sstring - digests string
  688.   -t       - runs time trial
  689.   -x       - runs test script
  690.   filename - digests file
  691.   (none)   - digests standard input
  692. */
  693. int main (argc, argv)
  694. int argc;
  695. Rivest                                                         [Page 17]
  696. RFC 1321              MD5 Message-Digest Algorithm            April 1992
  697. char *argv[];
  698. {
  699.   int i;
  700.   if (argc > 1)
  701. for (i = 1; i < argc; i++)
  702.    if (argv[i][0] == '-' && argv[i][1] == 's')
  703.      MDString (argv[i] + 2);
  704.    else if (strcmp (argv[i], "-t" ) == 0)
  705.      MDTimeTrial ();
  706.    else if (strcmp (argv[i], "-x" ) == 0)
  707.      MDTestSuite ();
  708.    else
  709.      MDFile (argv[i]);
  710.   else
  711. MDFilter ();
  712.   return (0);
  713. }
  714. /* Digests a string and prints the result.
  715. */
  716. static void MDString (string)
  717. char *string;
  718. {
  719.   MD_CTX context;
  720.   unsigned char digest[16];
  721.   unsigned int len = strlen (string);
  722.   MDInit (&context);
  723.   MDUpdate (&context, string, len);
  724.   MDFinal (digest, &context);
  725.   printf ("MD%d (\"%s\" ) = ", MD, string);
  726.   MDPrint (digest);
  727.   printf ("\n" );
  728. }
  729. /* Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte
  730.   blocks.
  731. */
  732. static void MDTimeTrial ()
  733. {
  734.   MD_CTX context;
  735.   time_t endTime, startTime;
  736.   unsigned char block[TEST_BLOCK_LEN], digest[16];
  737.   unsigned int i;
  738. Rivest                                                         [Page 18]
  739. RFC 1321              MD5 Message-Digest Algorithm            April 1992
  740.   printf
  741. ("MD%d time trial. Digesting %d %d-byte blocks ...", MD,
  742.   TEST_BLOCK_LEN, TEST_BLOCK_COUNT);
  743.   /* Initialize block */
  744.   for (i = 0; i < TEST_BLOCK_LEN; i++)
  745. block[i] = (unsigned char)(i & 0xff);
  746.   /* Start timer */
  747.   time (&startTime);
  748.   /* Digest blocks */
  749.   MDInit (&context);
  750.   for (i = 0; i < TEST_BLOCK_COUNT; i++)
  751. MDUpdate (&context, block, TEST_BLOCK_LEN);
  752.   MDFinal (digest, &context);
  753.   /* Stop timer */
  754.   time (&endTime);
  755.   printf (" done\n" );
  756.   printf ("Digest = " );
  757.   MDPrint (digest);
  758.   printf ("\nTime = %ld seconds\n", (long)(endTime-startTime));
  759.   printf
  760. ("Speed = %ld bytes/second\n",
  761.   (long)TEST_BLOCK_LEN * (long)TEST_BLOCK_COUNT/(endTime-startTime));
  762. }
  763. /* Digests a reference suite of strings and prints the results.
  764. */
  765. static void MDTestSuite ()
  766. {
  767.   printf ("MD%d test suite:\n", MD);
  768.   MDString ("" );
  769.   MDString ("a" );
  770.   MDString ("abc" );
  771.   MDString ("message digest" );
  772.   MDString ("abcdefghijklmnopqrstuvwxyz" );
  773.   MDString
  774. ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" );
  775.   MDString
  776. ("1234567890123456789012345678901234567890\
  777. 1234567890123456789012345678901234567890" );
  778. }
  779. /* Digests a file and prints the result.
  780. Rivest                                                         [Page 19]
  781.  
  782. RFC 1321              MD5 Message-Digest Algorithm            April 1992
  783. */
  784. static void MDFile (filename)
  785. char *filename;
  786. {
  787.   FILE *file;
  788.   MD_CTX context;
  789.   int len;
  790.   unsigned char buffer[1024], digest[16];
  791.   if ((file = fopen (filename, "rb" )) == NULL)
  792. printf ("%s can't be opened\n", filename);
  793.   else {
  794. MDInit (&context);
  795. while (len = fread (buffer, 1, 1024, file))
  796.    MDUpdate (&context, buffer, len);
  797. MDFinal (digest, &context);
  798. fclose (file);
  799. printf ("MD%d (%s) = ", MD, filename);
  800. MDPrint (digest);
  801. printf ("\n" );
  802.   }
  803. }
  804. /* Digests the standard input and prints the result.
  805. */
  806. static void MDFilter ()
  807. {
  808.   MD_CTX context;
  809.   int len;
  810.   unsigned char buffer[16], digest[16];
  811.   MDInit (&context);
  812.   while (len = fread (buffer, 1, 16, stdin))
  813. MDUpdate (&context, buffer, len);
  814.   MDFinal (digest, &context);
  815.   MDPrint (digest);
  816.   printf ("\n" );
  817. }
  818. /* Prints a message digest in hexadecimal.
  819. */
  820. static void MDPrint (digest)
  821. unsigned char digest[16];
  822. {
  823. Rivest                                                         [Page 20]
  824. RFC 1321              MD5 Message-Digest Algorithm            April 1992
  825.   unsigned int i;
  826.   for (i = 0; i < 16; i++)
  827. printf ("%02x", digest[i]);
  828. }
  829. A.5 Test suite
  830.    The MD5 test suite (driver option "-x" ) should print the following
  831.    results:
  832. MD5 test suite:
  833. MD5 ("" ) = d41d8cd98f00b204e9800998ecf8427e
  834. MD5 ("a" ) = 0cc175b9c0f1b6a831c399e269772661
  835. MD5 ("abc" ) = 900150983cd24fb0d6963f7d28e17f72
  836. MD5 ("message digest" ) = f96b697d7cb7938d525a2f31aaf161d0
  837. MD5 ("abcdefghijklmnopqrstuvwxyz" ) = c3fcd3d76192e4007dfb496cca67e13b
  838. MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ) =
  839. d174ab98d277d9f5a5611c2c9f419d9f
  840. MD5 ("123456789012345678901234567890123456789012345678901234567890123456
  841. 78901234567890" ) = 57edf4a22be3c955ac49da2e2107b67a
  842. Security Considerations
  843.    The level of security discussed in this memo is considered to be
  844.    sufficient for implementing very high security hybrid digital-
  845.    signature schemes based on MD5 and a public-key cryptosystem.
  846. Author's Address
  847.    Ronald L. Rivest
  848.    Massachusetts Institute of Technology
  849.    Laboratory for Computer Science
  850.    NE43-324
  851.    545 Technology Square
  852.    Cambridge, MA  02139-1986
  853.    Phone: (617) 253-5880
  854.    EMail: rivest@theory.lcs.mit.edu
  855. Rivest                                                         [Page 21]

n°64866
gilou
Modérateur
Modzilla
Posté le 13-10-2001 à 01:46:15  profilanswer
 

utilises cperf ou gperf, disponibles chez gnu:

Citation :

GNU gperf is a perfect hash function generator. For a given list of strings, it produces a hash function and hash table in the form of C or C++ code, for looking up a value depending on the input string. The hash function is 'perfect,' which means that the hash table has no collisions, and the hash table lookup needs a single string comparison only.  
GNU gperf is highly customizable. There are options for generating C and C++ code, for emitting 'switch' statements or nested 'ifs' instead of a hash table, and for tuning the algorithm that gperf uses.


A+,

 

[edtdd]--Message édité par gilou--[/edtdd]

n°64899
barbarella
Posté le 13-10-2001 à 13:45:56  profilanswer
 

slt,
 
d'abord je tiens a vous remercier de l'aide que vous m'avez apporté pour mon petit problème :)
 
Mais je vais rester dans l'immédiat avec ma petite procedure dichotomique. Effectivement la taille de ma liste de mot n'est pas dramatique de plus mon algo dicho est très performant d'autant plus que j'ai pu segmenter le tableau pour diminuer le nombre de comparaisons.

n°64900
flo850
moi je
Posté le 13-10-2001 à 13:46:59  profilanswer
 

autrement , la table de hachage est imposée ?
sinon un AVL c'est pas mal non plus les perfs st en log(n) pour la recherche l'ajout et la suppression d'element pour une taille totalement dynamique
en plus avec une petite pile , tu derecursive tout et tu as des perfs impressionnante ( je l'ai un C et en java , et meme en java ca va vite )

n°64902
barbarella
Posté le 13-10-2001 à 14:04:20  profilanswer
 

attendez,
 
je vais vous donner des p'tites stast pour vous montrer que ma situation n'est pas desespérée et que j'ai encore un peu le choix des algo. je reviens le temps de refaire une stat rapide.
 
flo850:
je suis deja en log(N), mais j'ai jamais pu comparer mon algo un autre performants . si tu pouvais le mettre ici :)

n°64903
barbarella
Posté le 13-10-2001 à 14:26:21  profilanswer
 

ok,
 
en 1 seconde j'arrive a faire plus de 4000000 (4 millions) de  
ret = find(mot); avec une comparaison moyenne 7,6 mots (7,6 strcmp(); par appel de find(mot) )sur une liste de mot de 6142 (taille des mots allant de 2 a 24). sur P3-933 NT4.
 
si la liste est non segmenter la comparaison moyenne monte a 11,8 strcmp par ret = find(mot).

mood
Publicité
Posté le 13-10-2001 à 14:26:21  profilanswer
 

n°64907
flo850
moi je
Posté le 13-10-2001 à 15:09:57  profilanswer
 

c'est clair que tu es en log(n )
pour l'avl ( ou arbre bicolore , c'est le meme principe ) je n'ai pas de donneés aussi precise mais sur le serveur de la fac , le fait de passer d'une liste triée non segmentée a un avl , j'ai divisé par 3 le tps de traitement .
en plus pour segmenter il faut savoir la taille de laliste non ? c'est du statique ? l'avantage de l'avl c'est que c'est totalement dynamique .
la structure de données est pas super violente  
en C je crois que le fichier .h doit faire 50 ligne et le .c dans les 300, donc ca reste raisonnable .

n°64933
barbarella
Posté le 13-10-2001 à 18:35:55  profilanswer
 

la journée a bogue aujourdhui :(, bon on reprends après cette petite interruption ;)
 
J'ai aussi des fonctions de gestion de chaine : insertion//recherche en dynamique. dans ce cas t'es obligé d'utliser un mécanisme d'indexage. J'ai utilisé un algo maison, car je n'apprécie pas la gestion en liste chaine avant/arrière, trop lourd pour l'indexation de chaine de mot. Il te faut 3 long soit 12 octets pour indexer un mot :(. J'utilise une autre méthode plus performante en recherche, moins performante en insertion. Mais dans mon cas la recherche est toujours plus importante.
 
Pour les segmentation d'une liste de mot de type chaine de cractère. Son efficacité est max quand elle est prédéfinie. maintenant il est possible de faire une variante dynamique.
le truc c'est de voir si le tps gagné en diminuant le nombre de comparaison est sup au temps nécessire pour gérer le tableau d'entier qui donne la position de chaque segment dans la liste trié de chaine de caract.  
 
par contre le nombre d'élément joue dans l'efficacité. effectivement le rapport X/Y tend vers zéro (X = nb comparaison moyenne sur l'ensemble du tableau Y = nb comparaison moyenne sur les segments) il faut dans ce cas re-segmenter, mais vu la répartition non-uniforme des mots (en général) il faut dans cas faire de la segmentation partielle. En dynamique ça devient ininteressant, en statique peut-être, faut voir.


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation

  fonction de hashage, Aie !

 

Sujets relatifs
Quelqu'un sait se servir de la fonction Shell_NotifyIcon?SVP Prgrammer un cercle en C++ (ou C) en fonction du cent. et du ray.
[PHP] Crée une fonction de recherche sur une base MySQL[matlab] paramètre optionnel dans une fonction ...
cherche nom de fonction en cEXCEL : Fonction SI imbriqué :( aidez moi
[php] pouvez vous tester (la fonction recherche de) mon forum ???[JAVASRIPT]redirection visteur en fonction de sa version de Windoz ?
Problème avec la fonction fopen[php] fonction graphics
Plus de sujets relatifs à : fonction de hashage, Aie !


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR