What is the encryption algorithm used by zip files?


I just want to know the exact formula (or algorithm) used for generating the pseudo random values used in encrypting the zip file. I am trying to create a password hacker(for zip files) and I also require to know how to verify if the random password generated by my program is correct. I have tried searching for an answer to this in Google but I could't find a direct solution.

I am trying to program this zip hacker in c++.

note: by formula (or algorithm) I meant: key derivation function. I just want the necessary information as quick as possible, that's why I posted it here!

Different versions of zip-files do it differently, but basically you have an encryption-header specifying what encryption is used according to the zip-file specification.

For example, the strong encryption header looks like below and specifies the encryption algorithm in the AlgID-field.

4.5.12 -Strong Encryption Header (0x0017):

    Value     Size     Description
    -----     ----     -----------
    0x0017    2 bytes  Tag for this "extra" block type
    TSize     2 bytes  Size of data that follows
    Format    2 bytes  Format definition for this record
    AlgID     2 bytes  Encryption algorithm identifier
    Bitlen    2 bytes  Bit length of encryption key
    Flags     2 bytes  Processing flags
    CertData  TSize-8  Certificate decryption extra field data
                       (refer to the explanation for CertData
                        in the section describing the
                        Certificate Processing Method under
                        the Strong Encryption Specification)