C 利用crypto 進行文字MD5校驗

2021-09-24 14:21:17 字數 1448 閱讀 9451

crypto++ 庫是乙個用c++ 編寫的免費的密碼類庫。為了校驗兩段文字是否一致(驗證資訊有沒有被修改),這裡用到的是雜湊演算法的md5。對長度大的資訊進行提煉(通過乙個hash函式),提煉過後的首席資訊官度小很多,得到的是乙個固定長度的值(hash值)。對於兩個資訊量很大的檔案通過比較這兩個值,就知道這兩個檔案是否完全一致(另外乙個檔案有沒有被修改)。從而避免了把兩個檔案中的資訊進行逐字逐句的比對,減少時間開銷。更具體的說明請移步社群鏈結

社群鏈結

官網:官方wiki:wiki/main_page

md5 wiki:wiki/md5

個人電腦是ubuntu系統,命令安裝即可,其他系統沒試過。

sudo apt-get install libcrypto++-dev libcrypto++-doc libcrypto++-utils
驗證字串是否一致

通常情況字串一致性驗證是逐字元比較,對於較長的文字,如檔案等,可用md5值來驗證。這裡是乙個字串驗證的例子。

#include #define cryptopp_enable_namespace_weak 1

#include #include #include #include int main(int argc, char* ar**) else

}

g++命令

g++ -o test test.cc -lcrypto++
計算檔案md5值

#include #define cryptopp_enable_namespace_weak 1

#include #include #include #include int main(int argc, char* ar**) ;

std::string strpath = "readme.md";

cryptopp::filesource(

strpath.c_str(), true,

new cryptopp::hashfilter(

md, new cryptopp::hexencoder(new cryptopp::arraysink(buf, size))));

std::string strhash = std::string(reinterpret_cast(buf), size);

std::cout << strhash.c_str() << std::endl;

}

g++命令

g++ -o test test.cc -lcrypto++
計算結果可以用以下命令驗證:

md5sum readme.md

利用文字標籤控制項進行文字顯示和生成超連結

using system using system.collections.generic using system.componentmodel using system.data using system.drawing using system.linq using system.text u...

利用python進行檔案操作

作者 wyh草樣 出處 什麼是檔案 檔案是系統儲存區域的乙個命名位置,用來儲存一些資訊,便於後續訪問。能夠在非易失性儲存器中實現持續性儲存,比如在硬碟上。當我們要讀取或者寫入檔案時,我們需要開啟檔案 在操作完畢時,我們需要關閉檔案,以便釋放和檔案操作相關的系統資源,因此,檔案操作的主要包括以下 開啟...

Python筆記 之 利用余弦相似性進行文字選擇

二維余弦相似度計算公式 cos cos theta cos x 1x 2 y1 y2x1 2 y1 2 x2 2 y2 2 over sqrt x12 y 12 x22 y2 2 x 1 x2 y1 y2 n維余弦相識度計算公式 cos cos theta cos k 1k n x1kx 2k k ...