Working with bits and SHA-1

Hey there. I am studying the SHA-1 algorithm for a project of mine and I was wondering a few things. First, how is SHA-1 supposed to be secure ? It produces a hash that does not depend on any private or even public key. Therefore, anyone that catches the SHA-1-encrypted data can decrypt it, given that they eventually find the original message was encrypted with SHA-1.

My second question is more about coding. SHA-1 depends **a lot** on working with bits. However, I am not too sure how I would achieve the different tasks (related to bits) required by the algorithm in C++. For example, each chunk is 512 bits-wide and the last chunk contains 64 bits of data, etc.

How would I hold **exactly**512 bits in a variable ? I know that variable types are not assured to be a fixed size, they vary from implementation to implementation.

The same question applies for the 64 bits (which are part of the 512-bits-chunk).

How would I then split everything up in smaller 32-bits chunks ? I think the most simple way to achieve this would be to have some kind of 32-bits variable type and then use it (since 32 is a factor of both 64 and 512) however I don't know how to achieve this either. I know some compilers support features such as __int32 and __int64 (those are on MSVC++ 2003) yet it'd be lovely if I could find a solution that works on all compilers.

Also, if you guys have suggestions on how to tackle this problem, they are much welcome ! I will continue my search and post my results, if any.

Thanks !