本文整理汇总了C++中MD5::init方法的典型用法代码示例。如果您正苦于以下问题:C++ MD5::init方法的具体用法?C++ MD5::init怎么用?C++ MD5::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MD5
的用法示例。
在下文中一共展示了MD5::init方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: md5test
void md5test() {
MD5 m;
MD5::char8 str[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
m.ComputMd5(str,sizeof(str) - 1);
m.printMd5();
MD5* md5 = new MD5();
md5->init();
md5->ComputMd5(str, sizeof(str) - 1);
std::string md5string = md5->GetMd5();
std::cout << "MD5 Value: " << md5string << endl;
delete(md5);
MD5 M;
m.init();
MD5::uchar8 str1[] = "ABCDEFGHIJKLMN";
MD5::uchar8 str2[] = "OPQRSTUVWXYZabcdefghijk";
MD5::uchar8 str3[] = "lmnopqrstuvwxyz";
m.UpdateMd5(str1,sizeof(str1) - 1);
m.UpdateMd5(str2,sizeof(str2) - 1);
m.UpdateMd5(str3,sizeof(str3) - 1);
m.Finalize();
m.printMd5();
}
示例2: main
int main()
{
string s;
while (getline(cin,s))
{
//for each bracket [] the content must be replied
//as many times as the number before
//since resulting string can be very long, we
//process the md5 value in sequences of 64 chars
//preprocess s so that we know for each bracket []
//the number of times it must be repeated
int n = s.size();
vector<int> initialBrackets (n,0); //in positions with [, brackets
//will contain the remaining loops; in positions with ],
//brackets will contain a pointer to its corresponding [
stack<int> unclosedBrackets; //pointers to unclosed brackets
int value = 0; //number of iterations
for (int i = 0; i < n; i++)
{
if (s[i] >= '0' and s[i] <= '9') //new digit
{
value *= 10;
value += s[i] - '0';
}
if (s[i] == '[')
{
initialBrackets[i] = value;
value = 0;
unclosedBrackets.push(i);
}
if (s[i] == ']')
{
initialBrackets[i] = unclosedBrackets.top();
unclosedBrackets.pop();
}
}
//ans will be updated with groups of 64 chars
MD5 ans;
ans.init();
char buffer[64];
int current = 0; //number of already read chars
int pointer = 0; //pointer to positions in s
vector<int> brackets = initialBrackets;
while (pointer < s.size())
{
if (s[pointer] >= 'a' and s[pointer] <= 'z')
{
buffer[current] = s[pointer];
current ++;
if (current >= 64)
{
current = 0;
ans.update (buffer, 64);
}
}
if (s[pointer] == '[') //next iteration
{
if (brackets[pointer] == 0) //new external iteration
brackets[pointer] = initialBrackets[pointer];
brackets[pointer] --;
}
if (s[pointer] == ']')
{
if (brackets[brackets[pointer]] > 0) //at least one more iteration
{
pointer = brackets[pointer] - 1; //compensate the final pointer++
}
}
pointer ++;
}
//update the last chars
ans.update (buffer, current);
ans.finalize();
cout << ans.hexdigest() << endl;
}
}