资源简介
利用libtomcrypt库进行sha1、sha512等的值计算
代码片段和文件信息
// hashtest.cpp : 定义控制台应用程序的入口点。
//
#include “stdafx.h“
#include
#include
int main(void){
int idx errnum;
unsigned long len;
unsigned char out[MAXBLOCKSIZE];
//const char buffer[4]=“0“;
/* register the hash */
if (register_hash(&md5_desc) == -1) {
printf(“Error registering MD5.\n“);
return -1;
}
if (register_hash(&sha1_desc) == -1) {
printf(“Error registering SHA1.\n“);
return -1;
}
if (register_hash(&sha256_desc) == -1) {
printf(“Error registering SHA256.\n“);
return -1;
}
if (register_hash(&sha512_desc) == -1) {
printf(“Error registering SHA512.\n“);
return -1;
}
/* get the index of the hash */
printf(“Please choose the hash name number\n1.md5 2.sha1 3.sha256 4.sha512\n“);
scanf(“%d“&num);
switch(num){
case 1: idx = find_hash(“md5“);
break;
case 2: idx = find_hash(“sha1“);
break;
case 3: idx = find_hash(“sha256“);
break;
case 4: idx = find_hash(“sha512“);
break;
default:
printf(“Error\n“);
return 0;
}
//idx = find_hash(buffer);
/* call the hash */
FILE* in=fopen(“s1.txt““rb“);
len = sizeof(out);
if ((err = hash_filehandle(idx in out &len)) != CRYPT_OK) {
printf(“Error hashing data: %s\n“ error_to_string(err));
return -1;
}
else{
printf(“s1.txt的hash值为:“);
for(int i=0;i printf(“%02x“out[i]);
}
printf(“\n“);
fclose(in);
in=fopen(“s2.txt““rb“);
if ((err = hash_filehandle(idx in out &len)) != CRYPT_OK) {
printf(“Error hashing data: %s\n“ error_to_string(err));
return -1;
}
else{
printf(“s2.txt的hash值为:“);
for(int i=0;i printf(“%02x“out[i]);
}
printf(“\n“);
fclose(in);
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 272 2013-12-02 21:24 S2.txt
文件 724914 2013-12-03 19:53 11283019-吴艳红-实验6 Hash算法.docx
文件 1751 2013-12-02 23:38 hashtest.cpp
文件 271 2013-12-02 21:24 S1.txt
----------- --------- ---------- ----- ----
727208 4
- 上一篇:273qkg.caj
- 下一篇:基于basys2的12进制计数器
评论
共有 条评论