|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 geen 于 2020-6-7 12:29 编辑
小甲鱼的课程 《带你学C带你飞》,第30节动动手题第0题的答案代码,复制下来也无法运行。请问各位大佬,这是哪里出了问题?我的操作系统是win10,Dev-C++ 5.11 。md5.h 文件已经放到了 .c 文件的相同路径下。
小甲鱼代码,如下:
- #include <stdio.h>
- #include <string.h>
- #include "md5.h"
- void md5(unsigned char *dest, unsigned char *src);
- void md5(unsigned char *dest, unsigned char *src)
- {
- int i;
- MD5_CTX md5;
- // 初始化
- MD5Init(&md5);
- // 传入明文字符串及其长度
- MD5Update(&md5, src, strlen((char *)src));
- // 得到加密后的字符串
- MD5Final(&md5, dest);
- }
- int main(void)
- {
- int i;
- unsigned char src[128];
- unsigned char dest[16];
- printf("请输入密码:");
- scanf("%s", src);
- printf("你输入的密码是:%s\n", src);
- md5(dest, src);
- printf("加密后的密码是:");
- for (i = 0; i < 16; i++)
- {
- printf("%02x", dest[i]);
- }
- putchar('\n');
- return 0;
- }
复制代码
md5.h 文件代码如下:
- #ifndef MD5_H
- #define MD5_H
- typedef struct
- {
- unsigned int count[2];
- unsigned int state[4];
- unsigned char buffer[64];
- }MD5_CTX;
- #define F(x,y,z) ((x & y) | (~x & z))
- #define G(x,y,z) ((x & z) | (y & ~z))
- #define H(x,y,z) (x^y^z)
- #define I(x,y,z) (y ^ (x | ~z))
- #define ROTATE_LEFT(x,n) ((x << n) | (x >> (32-n)))
- #define FF(a,b,c,d,x,s,ac) \
- { \
- a += F(b,c,d) + x + ac; \
- a = ROTATE_LEFT(a,s); \
- a += b; \
- }
- #define GG(a,b,c,d,x,s,ac) \
- { \
- a += G(b,c,d) + x + ac; \
- a = ROTATE_LEFT(a,s); \
- a += b; \
- }
- #define HH(a,b,c,d,x,s,ac) \
- { \
- a += H(b,c,d) + x + ac; \
- a = ROTATE_LEFT(a,s); \
- a += b; \
- }
- #define II(a,b,c,d,x,s,ac) \
- { \
- a += I(b,c,d) + x + ac; \
- a = ROTATE_LEFT(a,s); \
- a += b; \
- }
- void MD5Init(MD5_CTX *context);
- void MD5Update(MD5_CTX *context,unsigned char *input,unsigned int inputlen);
- void MD5Final(MD5_CTX *context,unsigned char digest[16]);
- void MD5Transform(unsigned int state[4],unsigned char block[64]);
- void MD5Encode(unsigned char *output,unsigned int *input,unsigned int len);
- void MD5Decode(unsigned int *output,unsigned char *input,unsigned int len);
- #endif
复制代码
|
|