int main(void) { char msg[MAXN + 1]; char digest[DIGEST_LENGTH]; int len; int num = 0, done1 = 0, done2 = 0; scanf("%s", msg); len = strlen(msg); while (!done1 || !done2) { num++; append(msg, len, num); MD5(msg, digest); if (!done1 && check_digest1(digest)) { printf("Found 5 zeros! N = %d\n", num); hex_digest(digest); done1 = 1; } if (!done2 && check_digest2(digest)) { printf("Found 6 zeros! N = %d\n", num); hex_digest(digest); done2 = 1; } } return 0; }
hasher::digest_rc md5_hasher::hex_digest(path_t const& fp) const { std::ifstream fh(fp.c_str(), std::ifstream::in | std::ifstream::binary); digest_rc rc(hex_digest(fh)); fh.close(); return rc; }
void update_operation::rollback() { auto file_manager = config_.file_manager; auto hasher = config_.hasher; // did we patch the file? keep in mind that if we did: // // - patched_path_ would point to the **original** file // - basis_path_ would point to the **patched** file // // to avoid confusion, we'll gonna rename the references to "original" and // "patched": const path_t &original_path(patched_path_); const string_t &original_checksum(basis_checksum); const path_t &modified_path(basis_path_); const string_t &modified_checksum(patched_checksum); if (!file_manager->is_readable(modified_path)) { return (void)STAGE_INVALID_STATE; } auto checksum = hasher->hex_digest(modified_path); if (checksum == modified_checksum) { // make sure the original still exists if (!file_manager->exists(original_path)) { error() << "Basis no longer exists in cache, can not rollback!"; return (void)STAGE_INVALID_STATE; } else if (hasher->hex_digest(original_path) != original_checksum) { error() << "Basis file seems to have changed, can not rollback!"; return (void)STAGE_INVALID_STATE; } // remove the modified file: file_manager->remove_file(modified_path); // and move the original file back in its place: file_manager->move(original_path, modified_path); } }
void create_operation::commit() { auto file_manager = config_.file_manager; auto hasher = config_.hasher; // in case of roll back, the source file will still be staged in the cache if ( file_manager->exists(cache_path_) && // just to be safe, double-check it's our own file! hasher->hex_digest(cache_path_) == src_checksum ) { file_manager->remove_file(cache_path_); } }
int main( int argc, char* argv[] ) { int i; byte digest[ SHA1_DIGEST_BYTES ]; int status; if ( argc == 1 ) { status = SHA1_file( "-", digest ); if ( status < 0 ) { perror( "(stdin)" ); } else { printf( "%s\n", hex_digest( digest ) ); } } else { for ( i = 1; i < argc; i++ ) { status = SHA1_file( argv[ i ], digest ); if ( status < 0 ) { perror( argv[ i ] ); return 1; } else { printf( "%s %s\n", hex_digest( digest ), argv[ i ] ); } } } return 0; }