salut, j'essaie de faire un cryptage en sha-1 mais mon resultat n'est pas du tout bon.

voici mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdio.h>
#include <stdlib.h>
 
 
char *sha(char *message){
//variables de base
int h0 = 0x67452301,h1 = 0xEFCDAB89,h2 = 0x98BADCFE;
int h3 = 0x10325476,h4 = 0xC3D2E1F0;
unsigned char *chaine=malloc(strlen(message)+512);
//on copie le message
strcpy(chaine,message);
int pos = strlen(chaine);
//on ajoute le bit 1 a la suite
chaine[pos] = 128;
int i;
//on ajoute des bits 0 jusqu'a 448 en gerant le modulo 512
for(i=0;((i+pos+1)*8)%512!=448;i++)
 chaine[i+pos+1]=0;
pos=i+pos+1;
char chainetemp[8];
//on a la taille du message
long long int taille=strlen(message);
//on convertit cette taille en chaine de 8 caracteres
sprintf(chainetemp,"%c%c%c%c%c%c%c%c",(char)(taille>>56),(char)(taille>>48),(char)(taille>>40),(char)(taille>>32)
,(char)(taille>>24),(char)(taille>>16),(char)(taille>>8),(char)taille);
//on copie cette chaine
for(i=0;i<8;i++)
   chaine[pos+i]=chainetemp[i];
pos=pos+i;
int word[80];
//on divise le message en 16 int de 32 bits
for(i=0;i<16;i++){
word[i]=chaine[i*4]<<24|chaine[i*4+1]<<16|chaine[i*4+2]<<8|chaine[i*4+3];
 
}
for(i=16;i<80;i++){
word[i]=(word[i-3]^word[i-8]^word[i-14]^word[i-16])<<1;
//void doc
}
//voir doc
int a = h0,b = h1, c = h2, d = h3, e = h4;
int f,k,temp;
for(i=0;i<79;i++){
if(i<20){
f=(b&c)|((!b)&d);
k=0x5A827999;
}
else if(i<40){
f=b^c^d;
k=0x6ED9EBA1;
}
else if(i<60){
f=(b & c) | (b & d) | (c & d);
k=0x8F1BBCDC;
}
else if(i<80){
f=b^c^d;
k=0xCA62C1D6;
}
temp = (a << 5) + f + e + k + word[i];
e = d;
d = c;
c = b << 30;
b = a;
a = temp;
}
 
h0+=a;
h1+=b;
h2+=c;
h3+=d;
h4+=e;
//on copie le resultat dans finish
char *finish = malloc(256);
sprintf(finish,"%08x %08x %08x %08x %08x",h0,h1,h2,h3,h4);
return finish;//on retourne le resultat
}
int main(int argc, char *argv[])
{
   while(1){
   char text[256];
   scanf("%s",text);
   printf("%s\n",sha(text));
}
  system("PAUSE");	
  return 0;
}
voici la doc que j'utilise : http://en.wikipedia.org/wiki/SHA_hash_functions

si vous voyez d'ou vient le probleme, merci de me le dire

delfare