文件名称:计算文件hash值的源代码,包含crc,md2,md4,md5,sha,sha1,sha256,ra-Calcu
文件大小:275KB
文件格式:ZIP
更新时间:2013-10-10 05:32:02
哈希算法 md5 crc sha2
int main(int argc, char *argv[]) { int i = 0; bool bOnce = true; char szPath[RH_MAX_PATH]; char szAbsPath[RH_MAX_PATH]; char szOrgPath[RH_MAX_PATH]; char szTemp[RH_MAX_BUFFER]; int iErrorCode = 0; CHashManager hashmgr; getcwd(szOrgPath, RH_MAX_PATH); //No arguments? if(argc == 1) { printInfo(); return(RH_NO_ARGS); } memset(szPath, 0, RH_MAX_PATH); bOnce = true; hashmgr.SelectAllAlgorithms(true); for(i = 1; i < argc; i++) { // Is the argument a path descriptor? if(isArgument(argv[i]) == false) { if(bOnce == false) strcat(szPath, " "); strcat(szPath, argv[i]); bOnce = false; // Next time add a space continue; } // The argument is an optional argument if(strlen(argv[i]) >= RH_MAX_BUFFER) continue; // Non-parsable option argument, ignore fmtArgument(argv[i], szTemp); // Format the argument, i.e. remove all special chars if(strcmp(szTemp, "help" ) == 0) printInfo(); if(strcmp(szTemp, "h" ) == 0) printInfo(); if(strcmp(szTemp, "?" ) == 0) printInfo(); if(strcmp(szTemp, "version" ) == 0) printInfo(); if(strcmp(szTemp, "v" ) == 0) printInfo(); if(strcmp(szTemp, "fullpath") == 0) hashmgr.SetOption(OPT_FULLPATH, true); if(strcmp(szTemp, "f" ) == 0) hashmgr.SetOption(OPT_FULLPATH, true); if(strcmp(szTemp, "nopath" ) == 0) hashmgr.SetOption(OPT_FULLPATH, false); if(strcmp(szTemp, "rcrsv" ) == 0) hashmgr.SetOption(OPT_RECURSIVE, true); if(strcmp(szTemp, "norcrsv" ) == 0) hashmgr.SetOption(OPT_RECURSIVE, false); if(strcmp(szTemp, "recur" ) == 0) hashmgr.SetOption(OPT_RECURSIVE, true); if(strcmp(szTemp, "norecur" ) == 0) hashmgr.SetOption(OPT_RECURSIVE, false); if(strcmp(szTemp, "r" ) == 0) hashmgr.SetOption(OPT_RECURSIVE, true); if(strcmp(szTemp, "all" ) == 0) hashmgr.SelectAllAlgorithms(true); if(strcmp(szTemp, "a" ) == 0) hashmgr.SelectAllAlgorithms(true); if(strcmp(szTemp, "none" ) == 0) hashmgr.SelectAllAlgorithms(false); if(strcmp(szTemp, "n" ) == 0) hashmgr.SelectAllAlgorithms(false); if(strcmp(szTemp, "crc16" ) == 0) hashmgr.SelectAlgorithm(HASHID_CRC16, true); if(strcmp(szTemp, "nocrc16" ) == 0) hashmgr.SelectAlgorithm(HASHID_CRC16, false); if(strcmp(szTemp, "crc16c" ) == 0) hashmgr.SelectAlgorithm(HASHID_CRC16CCITT, true); if(strcmp(szTemp, "nocrc16c") == 0) hashmgr.SelectAlgorithm(HASHID_CRC16CCITT, false); if(strcmp(szTemp, "crc32" ) == 0) hashmgr.SelectAlgorithm(HASHID_CRC32, true); if(strcmp(szTemp, "nocrc32" ) == 0) hashmgr.SelectAlgorithm(HASHID_CRC32, false); if(strcmp(szTemp, "fcs16" ) == 0) hashmgr.SelectAlgorithm(HASHID_FCS_16, true); if(strcmp(szTemp, "nofcs16" ) == 0) hashmgr.SelectAlgorithm(HASHID_FCS_16, false); if(strcmp(szTemp, "fcs32" ) == 0) hashmgr.SelectAlgorithm(HASHID_FCS_32, true); if(strcmp(szTemp, "nofcs32" ) == 0) hashmgr.SelectAlgorithm(HASHID_FCS_32, false); if(strcmp(szTemp, "ghash3" ) == 0) hashmgr.SelectAlgorithm(HASHID_GHASH_32_3, true); if(strcmp(szTemp, "noghash3") == 0) hashmgr.SelectAlgorithm(HASHID_GHASH_32_3, false); if(strcmp(szTemp, "ghash5" ) == 0) hashmgr.SelectAlgorithm(HASHID_GHASH_32_5, true); if(strcmp(szTemp, "noghash5") == 0) hashmgr.SelectAlgorithm(HASHID_GHASH_32_5, false); if(strcmp(szTemp, "gost" ) == 0) hashmgr.SelectAlgorithm(HASHID_GOST, true); if(strcmp(szTemp, "nogost" ) == 0) hashmgr.SelectAlgorithm(HASHID_GOST, false); if(strcmp(szTemp, "haval" ) == 0) hashmgr.SelectAlgorithm(HASHID_HAVAL, true); if(strcmp(szTemp, "nohaval" ) == 0) hashmgr.SelectAlgorithm(HASHID_HAVAL, false); if(strcmp(szTemp, "md2" ) == 0) hashmgr.SelectAlgorithm(HASHID_MD2, true); if(strcmp(szTemp, "nomd2" ) == 0) hashmgr.SelectAlgorithm(HASHID_MD2, false); if(strcmp(szTemp, "md4" ) == 0) hashmgr.SelectAlgorithm(HASHID_MD4, true); if(strcmp(szTemp, "nomd4" ) == 0) hashmgr.SelectAlgorithm(HASHID_MD4, false); if(strcmp(szTemp, "md5" ) == 0) hashmgr.SelectAlgorithm(HASHID_MD5, true); if(strcmp(szTemp, "nomd5" ) == 0) hashmgr.SelectAlgorithm(HASHID_MD5, false); if(strcmp(szTemp, "sha1" ) == 0) hashmgr.SelectAlgorithm(HASHID_SHA1 , true); if(strcmp(szTemp, "nosha1" ) == 0) hashmgr.SelectAlgorithm(HASHID_SHA1 , false); if(strcmp(szTemp, "sha256" ) == 0) hashmgr.SelectAlgorithm(HASHID_SHA2_256, true); if(strcmp(szTemp, "nosha256") == 0) hashmgr.SelectAlgorithm(HASHID_SHA2_256, false); if(strcmp(szTemp, "sha384" ) == 0) hashmgr.SelectAlgorithm(HASHID_SHA2_384, true); if(strcmp(szTemp, "nosha384") == 0) hashmgr.SelectAlgorithm(HASHID_SHA2_384, false); if(strcmp(szTemp, "sha512" ) == 0) hashmgr.SelectAlgorithm(HASHID_SHA2_512, true); if(strcmp(szTemp, "nosha512") == 0) hashmgr.SelectAlgorithm(HASHID_SHA2_512, false); if(strcmp(szTemp, "size32" ) == 0) hashmgr.SelectAlgorithm(HASHID_SIZE_32, true); if(strcmp(szTemp, "nosize32") == 0) hashmgr.SelectAlgorithm(HASHID_SIZE_32, false); if(strcmp(szTemp, "tiger" ) == 0) hashmgr.SelectAlgorithm(HASHID_TIGER, true); if(strcmp(szTemp, "notiger" ) == 0) hashmgr.SelectAlgorithm(HASHID_TIGER, false); } // Check if a path is in the arguments bOnce = false; for(i = 1; i < argc; i++) if(isArgument(argv[i]) == 0) bOnce = true; if(bOnce == false) return RH_NO_PATH; // Silently exit fmtPath(szPath); strcpy(szAbsPath, szPath); pathonly(szAbsPath); if(strlen(szAbsPath) != 0) { if(chdir(szAbsPath) != 0) { printf("ERROR! Cannot change to directory: "); printf(szAbsPath); printf(CPS_NEWLINE); return RH_DIRECTORY_ERROR; } } fileonly(szPath); iErrorCode = hashmgr.HashPath(szAbsPath, szPath); if(chdir(szOrgPath) != 0) return RH_DIRECTORY_ERROR; return iErrorCode; }
【文件预览】:
rhsyscfg.h
docs
----gnugpl2.txt(15KB)
----rehash.html(10KB)
----rehash.jpg(109KB)
rehash.dsp
rehash.cpp
clutil.cpp
rehash.dsw
algo
----md5.h(4KB)
----ghash.cpp(1KB)
----sha1.h(2KB)
----fcs.h(949B)
----sha1.cpp(9KB)
----crc16.cpp(4KB)
----gosthash.cpp(12KB)
----fcs.cpp(7KB)
----md4.h(2KB)
----sizehash.cpp(776B)
----md5.cpp(12KB)
----ghash.h(846B)
----sha2.h(4KB)
----md4.cpp(8KB)
----crc32.h(763B)
----md2.cpp(3KB)
----tiger.h(716B)
----sha2.cpp(25KB)
----sizehash.h(772B)
----md2.h(475B)
----haval.cpp(31KB)
----crc32.cpp(4KB)
----gosthash.h(931B)
----crc16.h(970B)
----haval.h(4KB)
----tiger.cpp(45KB)
rehash.h
hashmgr.h
hashmgr.cpp
testvect
----testvect.txt(6KB)
----docs()
--------tiger-nessie.txt(228KB)
--------rfc1321.txt(36KB)
--------rfc1320.txt(33KB)
--------haval.cert(684B)
--------rfc1319.txt(26KB)
----testfiles()
--------tiger_long.txt(125B)
--------nothing.txt(0B)
--------message digest.txt(14B)
--------abc_plus_minus.txt(128B)
--------abc-extended.txt(62B)
--------numbers.txt(80B)
--------abc.txt(3B)
--------tiger.txt(5B)
--------abc-complete-numbers.txt(62B)
--------suppose.txt(50B)
--------1million_a.txt(977KB)
--------a.txt(1B)
--------abc-mixed.txt(56B)
--------abc-complete.txt(26B)
clutil.h