91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 995KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2021-06-14
  • 語言: C/C++
  • 標簽: SHA-256??SHA??C++??哈希??

資源簡介

SHA-256算法的C++實現及demo

資源截圖

代碼片段和文件信息

#include?“sha256.h“

///?same?as?reset()
SHA256::SHA256()
{
??reset();
}

///?restart
void?SHA256::reset()
{
??m_numBytes???=?0;
??m_bufferSize?=?0;

??//?according?to?RFC?1321
??m_hash[0]?=?0x6a09e667;
??m_hash[1]?=?0xbb67ae85;
??m_hash[2]?=?0x3c6ef372;
??m_hash[3]?=?0xa54ff53a;
??m_hash[4]?=?0x510e527f;
??m_hash[5]?=?0x9b05688c;
??m_hash[6]?=?0x1f83d9ab;
??m_hash[7]?=?0x5be0cd19;
}

namespace
{
??inline?uint32_t?rotate(uint32_t?a?uint32_t?c)
??{
????return?(a?>>?c)?|?(a?<??}

??inline?uint32_t?swap(uint32_t?x)
??{
return?_byteswap_ulong(x);
??}

??//?mix?functions?for?processBlock()
??inline?uint32_t?f1(uint32_t?e?uint32_t?f?uint32_t?g)
??{
????uint32_t?term1?=?rotate(e?6)?^?rotate(e?11)?^?rotate(e?25);
????uint32_t?term2?=?(e?&?f)?^?(~e?&?g);?//(g?^?(e?&?(f?^?g)))
????return?term1?+?term2;
??}

??inline?uint32_t?f2(uint32_t?a?uint32_t?b?uint32_t?c)
??{
????uint32_t?term1?=?rotate(a?2)?^?rotate(a?13)?^?rotate(a?22);
????uint32_t?term2?=?((a?|?b)?&?c)?|?(a?&?b);?//(a?&?(b?^?c))?^?(b?&?c);
????return?term1?+?term2;
??}
}


///?process?64?bytes
void?SHA256::processBlock(const?void*?data)
{
??//?get?last?hash
??uint32_t?a?=?m_hash[0];
??uint32_t?b?=?m_hash[1];
??uint32_t?c?=?m_hash[2];
??uint32_t?d?=?m_hash[3];
??uint32_t?e?=?m_hash[4];
??uint32_t?f?=?m_hash[5];
??uint32_t?g?=?m_hash[6];
??uint32_t?h?=?m_hash[7];

??//?data?represented?as?16x?32-bit?words
??const?uint32_t*?input?=?(uint32_t*)?data;
??//?convert?to?big?endian
??uint32_t?words[64];
??int?i;
??for?(i?=?0;?i?#if?defined(__BYTE_ORDER)?&&?(__BYTE_ORDER?!=?0)?&&?(__BYTE_ORDER?==?__BIG_ENDIAN)
????words[i]?=??????input[i];
#else
????words[i]?=?swap(input[i]);
#endif

??uint32_t?xy;?//?temporaries

??//?first?round
??x?=?h?+?f1(efg)?+?0x428a2f98?+?words[?0];?y?=?f2(abc);?d?+=?x;?h?=?x?+?y;
??x?=?g?+?f1(def)?+?0x71374491?+?words[?1];?y?=?f2(hab);?c?+=?x;?g?=?x?+?y;
??x?=?f?+?f1(cde)?+?0xb5c0fbcf?+?words[?2];?y?=?f2(gha);?b?+=?x;?f?=?x?+?y;
??x?=?e?+?f1(bcd)?+?0xe9b5dba5?+?words[?3];?y?=?f2(fgh);?a?+=?x;?e?=?x?+?y;
??x?=?d?+?f1(abc)?+?0x3956c25b?+?words[?4];?y?=?f2(efg);?h?+=?x;?d?=?x?+?y;
??x?=?c?+?f1(hab)?+?0x59f111f1?+?words[?5];?y?=?f2(def);?g?+=?x;?c?=?x?+?y;
??x?=?b?+?f1(gha)?+?0x923f82a4?+?words[?6];?y?=?f2(cde);?f?+=?x;?b?=?x?+?y;
??x?=?a?+?f1(fgh)?+?0xab1c5ed5?+?words[?7];?y?=?f2(bcd);?e?+=?x;?a?=?x?+?y;

??//?secound?round
??x?=?h?+?f1(efg)?+?0xd807aa98?+?words[?8];?y?=?f2(abc);?d?+=?x;?h?=?x?+?y;
??x?=?g?+?f1(def)?+?0x12835b01?+?words[?9];?y?=?f2(hab);?c?+=?x;?g?=?x?+?y;
??x?=?f?+?f1(cde)?+?0x243185be?+?words[10];?y?=?f2(gha);?b?+=?x;?f?=?x?+?y;
??x?=?e?+?f1(bcd)?+?0x550c7dc3?+?words[11];?y?=?f2(fgh);?a?+=?x;?e?=?x?+?y;
??x?=?d?+?f1(abc)?+?0x72be5d74?+?words[12];?y?=?f2(efg);?h?+=?x;?d?=?x?+?y;
??x?=?c?+?f1(hab)?+?0x80deb1fe?+?words[13];?y?=?f2(def);?g?+=?x;?c?=?x?+?y;
??x?=?b?+?f1(gha)?+?0x9bdc06a7?+?words[14];?y?=?f2(cde);?f?+=?x;?b?=?x?+?y;
??x?=?a?+?f1(fgh)?+?0xc19bf174?+?words[15

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-05-31?14:54??testsha256\
?????目錄???????????0??2016-05-31?14:35??testsha256\Debug\
?????文件???????85504??2016-05-31?14:53??testsha256\Debug\testsha256.exe
?????文件??????578048??2016-05-31?14:53??testsha256\Debug\testsha256.ilk
?????文件?????1126400??2016-05-31?14:53??testsha256\Debug\testsha256.pdb
?????目錄???????????0??2016-05-31?14:53??testsha256\testsha256\
?????目錄???????????0??2016-05-31?14:53??testsha256\testsha256\Debug\
?????文件??????174855??2016-05-31?14:52??testsha256\testsha256\Debug\sha256.obj
?????文件???????11147??2016-05-31?14:35??testsha256\testsha256\Debug\stdafx.obj
?????文件????????1445??2016-05-31?14:53??testsha256\testsha256\Debug\testsha256.log
?????文件??????159772??2016-05-31?14:53??testsha256\testsha256\Debug\testsha256.obj
?????文件?????2162688??2016-05-31?14:35??testsha256\testsha256\Debug\testsha256.pch
?????目錄???????????0??2016-05-31?14:53??testsha256\testsha256\Debug\testsha256.tlog\
?????文件???????27858??2016-05-31?14:53??testsha256\testsha256\Debug\testsha256.tlog\CL.read.1.tlog
?????文件????????1980??2016-05-31?14:53??testsha256\testsha256\Debug\testsha256.tlog\CL.write.1.tlog
?????文件????????1940??2016-05-31?14:53??testsha256\testsha256\Debug\testsha256.tlog\cl.command.1.tlog
?????文件????????1442??2016-05-31?14:53??testsha256\testsha256\Debug\testsha256.tlog\link.command.1.tlog
?????文件????????3044??2016-05-31?14:53??testsha256\testsha256\Debug\testsha256.tlog\link.read.1.tlog
?????文件?????????674??2016-05-31?14:53??testsha256\testsha256\Debug\testsha256.tlog\link.write.1.tlog
?????文件?????????163??2016-05-31?14:53??testsha256\testsha256\Debug\testsha256.tlog\testsha256.lastbuildstate
?????文件??????371712??2016-05-31?14:53??testsha256\testsha256\Debug\vc120.idb
?????文件??????430080??2016-05-31?14:53??testsha256\testsha256\Debug\vc120.pdb
?????文件????????1531??2016-05-31?14:26??testsha256\testsha256\ReadMe.txt
?????文件???????13115??2016-05-31?14:51??testsha256\testsha256\sha256.cpp
?????文件????????1247??2016-05-31?14:50??testsha256\testsha256\sha256.h
?????文件?????????216??2016-05-31?14:26??testsha256\testsha256\stdafx.cpp
?????文件?????????234??2016-05-31?14:26??testsha256\testsha256\stdafx.h
?????文件?????????236??2016-05-31?14:26??testsha256\testsha256\targetver.h
?????文件?????????346??2016-05-31?14:53??testsha256\testsha256\testsha256.cpp
?????文件????????4631??2016-05-31?14:35??testsha256\testsha256\testsha256.vcxproj
?????文件????????1495??2016-05-31?14:34??testsha256\testsha256\testsha256.vcxproj.filters
............此處省略3個文件信息

評論

共有 條評論