PhilLu
Messages postés251Date d'inscriptionlundi 9 novembre 2009StatutMembreDernière intervention11 mai 2021
-
15 mai 2010 à 22:35
PhilLu
Messages postés251Date d'inscriptionlundi 9 novembre 2009StatutMembreDernière intervention11 mai 2021
-
22 mai 2010 à 15:48
Bonjour,
Je suis débutant et je crée qq prgm, mais cette fois je dois générer une clé SHA1 d'un texte contenu dans un mémo.
Je cherche la solution la plus simple possible!!!
Toutes les solutons que j'ai trouvée (composants) m'ont posé des problèmes d'installation!!!
Merci pour votre aide,
PhilLu.
{$R *.dfm}
uses TinyHash; { unité des fonctions de hash }
procedure TForm1.Button1Click(Sender: TObject);
begin
Year:=intToStr(yearof(now));
If Monthof(now)<10 then Month:='0'+intTostr(Monthof(now))else Month:=intTostr(Monthof(now)) ;
If Dayof(now)<10 then Day:='0'+intTostr(dayof(now))else Day:=intTostr(Dayof(now)) ;
If Hourof(now)<10 then Hour:='0'+intTostr(Hourof(now))else Hour:=intTostr(Hourof(now)) ;
If Minuteof(now)<10 then Min:='0'+intTostr(Minuteof(now))else Min:=intTostr(Minuteof(now)) ;
If Secondof(now)<10 then Sec:='0'+intTostr(Secondof(now))else Sec:=intTostr(Secondof(now)) ;
DT:= year+month+day+Hour+Min+Sec;
Memo1.Lines.SaveToFile('temp.txt');
AssignFile(F,'temp.txt');
reset(F);
repeat
readln(F,S);
If pos('Confirmation de livraison ',S)>0 then BLNO:=copy(S,pos('Confirmation de livraison ',S)+26,6);
If pos('Delivery to cust no',S)>0 then NOCLIAB:=copy(S,pos('Delivery to cust no',S)+23,7);
If pos('Reference client:',S)>0 then NOCLIEXT:=copy(S,pos('Reference client:',S)+21,length(S));
If pos('No de commande:',S)>0 then REFCMD:=copy(S,pos('No de commande:',S)+21,6);
until eof(F);
I:=0;
reset(F);
repeat
readln(F,S);
until pos('Reference: no de serie: Commande: Reste Livre:',S)>0 ;
begin
Readln(F,S);
repeat
i:=i+1;
StringGrid1.RowCount:=StringGrid1.RowCount+1;
If S='--------------------------------------------------------------------------------' then else readln(F,S);
Readln(F,S);
If S<>'' then
begin
StringGrid1.cells[0,i]:=Copy(S,0,pos(' ',S)-1);
T:=Copy(S,17,length(S));
StringGrid1.cells[1,i]:=Copy(S,17,pos(' ',T)-1);//
StringGrid1.cells[2,i]:=Copy(S,43,pos(' ',S)-2);
StringGrid1.cells[3,i]:=Copy(S,56,pos(' ',S)-2);
StringGrid1.cells[4,i]:=Copy(S,69,pos(' ',S)-1);
end;
Readln(F,S);
StringGrid1.cells[5,i]:=Copy(S,17,length(S){pos(' ',S)-1});
Readln(F,S);
If S<>'--------------------------------------------------------------------------------' then
StringGrid1.cells[6,i]:=Copy(S,38,length(S){pos(' ',S)-1}) else
begin
StringGrid1.cells[6,i]:='';
end;
until eof(F);
end;
Memo1.Clear;
Memo1.Lines.Append('VERSION | V1.00');
Memo1.Lines.Append('ENTETENUMCLI | '+NOCLIAB);
Memo1.Lines.Append('ENTETENUMBL | '+BLNO);
Memo1.Lines.Append('ENTETENUMINC | '+'1');
Memo1.Lines.Append('ENTETEREFCMD | '+REFCMD);
For I:=1 to StringGrid1.RowCount-1 do
begin
Memo1.Lines.Append('LIGNEBL | '+IntToStr(i)+' | '+StringGrid1.cells[0,i]+' | '+StringGrid1.cells[4,i]+' | '+StringGrid1.cells[1,i]+' | '+StringGrid1.cells[6,i]+' | '+StringGrid1.cells[5,i]);
end;
//calcul du hash -------------------------------------------------
type
TStreamBuffer = {$IfDef UsePacked} packed {$EndIf} array[0..StreamBufferSize-1] of byte;
procedure DataToStr(const Data; const DataSize : LongInt; var R : AnsiString); {$IfDef UseInline} inline; {$EndIf}
var
pR : PAnsiChar;
pB : ^byte;
N : LongInt;
const
Dig : array[$0..$F] of AnsiChar = '0123456789abcdef';
begin
SetLength(R, DataSize shl 1);
pR := PAnsiChar(R);
pB := @Data;
for N := 0 to DataSize-1 do begin
pR[0] := Dig[pB^ shr 4];
pR[1] := Dig[pB^ and $F];
inc(pR,2);
inc(pB);
end;
end;
procedure Min(const A,B : LongInt; var R : LongInt); {$IfDef UseInline} inline; {$EndIf}
begin
if A < B then R := A else R := B;
end;
{ SHA1 ------------------------------------------------------------------------------------------- }
function SHA1Compare(const DigA,DigB : TSHA1Digest) : boolean;
begin
result := CompareMem(@DigA,@DigB, SHA1_DIG_SIZE);
end;
function SHA1ToStr(const Digest : TSHA1Digest) : AnsiString;
begin
DataToStr(Digest, SHA1_DIG_SIZE, Result);
end;
function SHA1(Stream : TStream; const CallBack : TCallBackHashProc) : TSHA1Digest;
var StreamBuffer : TStreamBuffer;
RBS : LongInt;
PassCount : LongInt;
CT : SHA1_CTX;
begin
if not assigned(Stream) then
exit;
PassCount := 0;
SHA1Init(@CT);
repeat
RBS := Stream.Read(StreamBuffer, StreamBufferSize);
if RBS > 0 then
begin
SHA1Update(@CT, StreamBuffer, RBS);
inc(PassCount);
CallBack(Stream.Size, Stream.Position, PassCount);
end;
until RBS < StreamBufferSize;
SHA1Final(@CT,@Result);
end;
function SHA1(Stream : TStream) : TSHA1Digest;
var StreamBuffer : TStreamBuffer;
RBS : LongInt;
CT : SHA1_CTX;
begin
if not assigned(Stream) then
exit;
SHA1Init(@CT);
repeat
RBS := Stream.Read(StreamBuffer, StreamBufferSize);
if RBS > 0 then
SHA1Update(@CT, StreamBuffer, RBS);
until RBS < StreamBufferSize;
SHA1Final(@CT,@Result);
end;
function SHA1(const S : AnsiString) : TSHA1Digest;
var CT : SHA1_CTX;
begin
SHA1Init(@CT);
SHA1Update(@CT, PAnsiChar(S)^, Length(S));
SHA1Final(@CT, @Result);
end;
function SHA1(const Buffer; const BufferSize : LongInt) : TSHA1Digest;
var CT : SHA1_CTX;
begin
SHA1Init(@CT);
SHA1Update(@CT, Buffer, BufferSize);
SHA1Final(@CT, @result);
end;
{ ADVAPI32 --------------------------------------------------------------------------------------- }
const
LIB_ADVAPI32 = 'advapi32.dll';
{ SHA1 imports }
procedure SHA1Init; external LIB_ADVAPI32 name 'A_SHAInit';
procedure SHA1Update; external LIB_ADVAPI32 name 'A_SHAUpdate';
procedure SHA1Final; external LIB_ADVAPI32 name 'A_SHAFinal';
PhilLu
Messages postés251Date d'inscriptionlundi 9 novembre 2009StatutMembreDernière intervention11 mai 2021 22 mai 2010 à 15:48
En fait je copie un texte et je le colle dans un memo.
Je vérifie que le curseur soi à la fin de la dernière ligne et pas au début de la ligne suivante.
Est-ce que dans un mémo les blancs entre la fin du texte sont pris en compte ou un cr/lf est compté dans le hash?
je suis un peu perdu en fait et je ne trouve pas de doc à ce sujet!!!
Merci,
A+
Phil.