crc32校验文件数据
来源:互联网 发布:驯化狼 知乎 编辑:程序博客网 时间:2024/05/21 21:39
# include <stdio.h># include <string.h>unsigned int POLYNOMIAL = 0xEDB88320;unsigned char have_table = 0;unsigned int table[256];void make_table(){ int i, j; have_table = 1 ; for (i = 0 ; i < 256 ; i++) for (j = 0, table[i] = i ; j < 8 ; j++) table[i] = (table[i]>>1)^((table[i]&1)?POLYNOMIAL:0) ;}unsigned int crc32(unsigned int crc, char *buff, int len){ int i; if (!have_table) make_table() ; crc = ~crc; for (i = 0; i < len; i++) crc = (crc >> 8) ^ table[(crc ^ buff[i]) & 0xff]; return ~crc;}int crc32_file(char *filename, unsigned int *result){ FILE *file; int len; unsigned char buffer[1024];//unsigned int crc = 0xffffffff; unsigned int crc = 0x0; if ((file = fopen (filename, "rb")) == NULL) { printf("open %s fail here\n", filename); return -1; } else { while ((len = fread (buffer, 1, 1024, file)) != 0) { crc = crc32(crc, buffer, len); } *result = crc; fclose (file); return 0; }}/*int main(int argv, char **argc){ FILE *fp; char s[] = "12345"; int ret = -1; unsigned char digit[16]; char buf[256]; int i; unsigned int result; char cmd[256]; printf("start crc32 here~~~~~\n"); if (argv == 3) { //ret = crc32_file(argc[1], digit); ret = crc32_file(argc[1], &result); if (ret == 0) { printf("ret is 0x%x\n",result); sprintf(cmd, "echo 0x%x > %s.%s",result, argc[1], argc[2]); system(cmd); } else { printf("open %s fail\n", argc[1]); } } else { printf("0X%08x\n", crc32(0, s, strlen(s))); return -1; } return 0;}*/
头文件crc32.h
#ifndef __CRC32_H#define __CRC32_H#ifdef __cplusplusextern "C"{#endifextern unsigned int POLYNOMIAL;extern unsigned char have_table;extern unsigned int table[256];void make_table(void);int crc32_file(char *filename, unsigned int *result);#ifdef __cplusplus}#endif#endif
阅读全文
0 0
- crc32校验文件数据
- delphi 文件CRC32校验
- 使用CRC32 校验png数据
- 使用CRC32 校验png数据
- CRC32校验
- crc32校验
- CRC32校验
- 文件校验MD5、SHA1、CRC32、sha256、cksum
- 文件Crc32校验追加以及文件Crc32校验(0xEDB88320)
- CRC16校验、CRC32校验
- crc16,crc32校验
- java 实现CRC32校验
- 闲话CRC32校验
- CRC32校验C代码
- 什么是CRC32校验
- java 实现CRC32校验
- crc32取余校验
- java 实现CRC32校验
- 求一个数的绝对值
- 解决ubuntu的apt-get命令被占用
- 建模常用的概念介绍1: WOE、IV
- JavaScript,点击其他区域隐藏
- Ubuntu 14.04 下OpenDayLight SFC 配置
- crc32校验文件数据
- E
- linux 安装telnet命令及使用
- 从零写USB摄像头驱动之实现数据传输1_框架
- Listener refused the connection with the following error 错误解决
- 中层视觉:使用随机方法的分割与拟合
- Dubbo 并发调优的几个参数
- 查询中文时,mariadb报‘UnicodeEncodeError:'latin-1' codec can't encode character’
- 一些简单的程序