尝试理解MD5算法
我正在尝试用 C 语言使用 MD5 做一些事情(后来又尝试使用 SHA1 算法做一些事情)。 我的主要问题是我从来没有真正在 C 中做过任何复杂的事情,只是简单的事情(没有像指向指针或结构的指针那样)。
我包含了文件 md5.c
和 md5.h
在我的 C 项目中(使用代码块),但唯一的问题是我不太明白如何使用它。 我已经阅读并重新阅读了代码,但我不明白如何使用这些函数将“示例”转换为 MD5 哈希值。
我已经有一段时间没有做过 C 编程了(主要是 php),所以我在这里有点迷失。 基本上我要问的是一些用法示例。 它们是通过 md5main.c 文件提供的,但我不理解它们。
我在这里的目标很高吗? 我应该停止这一切并重新开始阅读 C 书吗?或者任何人都可以给我一些指示,看看我是否能解决这个问题。
谢谢。
I am trying to do something in C with the MD5 (and latter trying to do something with the SHA1 algorithm). My main problem is that I never really did anything complex in C, just simple stuff (nothing like pointers to pointers or structs).
I included the files md5.c
and md5.h
in my C project (using codeblocks) but the only problem is that I don't really understand how to use it. I have read and re-read the code and I don't understand how I use those functions to turn 'example' into a MD5 hash.
I haven't done C programming in a while (mostly php) so I am a bit lost here.
Basically what I am asking is for some examples of usage. They are provided via the md5main.c
file but I don't understand them.
Am I aiming high here? Should I stop all this and start reading the C book again or can anyone give me some pointers and see if I can figure this out.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你选择了最糟糕的东西来看待(这不是你自己的错)。 加密和哈希类型算法将以最奇怪的方式使用语言来完成他们需要快速完成的数学类型。 它们几乎肯定是混乱且难以理解的。 另外,你需要深入数学才能真正理解它们。
如果您只想要一个哈希算法,请获取众所周知的实现并将其用作黑匣子。 不要尝试自己实现它,您几乎肯定会在实现中引入一些加密弱点。
编辑:如果您想要有关加密的优秀书籍(或资源),要充分响应,请参阅 Bruce Schneier。 应用密码学是经典。
I think you picked about the worst thing to look at (by no fault of your own). Encryption and hash type algorithms are going to make the strangest use of the language possible to do the type of math they need to do quickly. They are almost guaranteed to be obfuscated and difficult to understand. Plus, you will need to get bogged down in math in order to really understand them.
If you just want a hashing algorithm, get a well-known implementation and use it as a black box. Don't try and implement it yourself, you will almost certainly introduce some cryptographic weakness into the implementation.
Edit: To be fully responsive if you want great books (or resources) on encryption, look to Bruce Schneier. Applied Cryptography is a classic.
虽然我同意 Bill 的观点,但如果你想真正理解你在做什么,你应该回到 C 书。 但是,为了提供帮助,我修改并注释了 md5main.c 中的一些代码...
希望这有帮助!
While I agree with Bill, you should go back to the C book if you want to really understand what you're doing. But, in an effort to help, I've modified and commented some of the code from md5main.c...
Hope this helps!
你应该停止这一切,重新开始阅读 C 书。
我的经验是,当我尝试学习一门新的编程语言时,尝试同时实现一个复杂的项目是不切实际的。 您应该用 C 语言进行简单的练习,直到您熟悉该语言为止,然后解决诸如实现 MD5 或集成现有实现之类的问题。
顺便说一句,阅读代码是一种与编写代码不同的技能。 这两种技能之间存在差异,但都要求您很好地理解语言。
You should stop all this and start reading the C book again.
My experience is that when I am trying to learn a new programming language, it's not practical to try implementing a complex project at the same time. You should do simple exercises in C until you are comfortable with the language, and then tackle something like implementing MD5 or integrating an existing implementation.
By the way, reading code is a skill different from writing code. There are differences between these two skills, but both require that you understand the language well.