如何处理用C大整数 [英] How to handle big integers in C

查看:123
本文介绍了如何处理用C大整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要实现的加密算法。所以我需要一个合适的数据类型来处理整数有很多的数字。

I want to implement cryptography algorithms. So I need a suitable data type to handle integers with a lot of digits.

最近很多语言,比如Java,Python和Ruby提供原生的方式来做到这一点。不过,我在编程的C,我想知道什么是最好的方式来实现基本的操作也最简单的方法。

Many recent languages, such as Java, Python and Ruby provide native ways to do this. However, I'm programming in C, and I was wondering what is the best way and easiest way to implement elementary operations there.

我想它写,没有任何外部库。我想到了两个选项:

I would like to write it without any external library. I thought about two options:


  1. 使用字符数组(如字符串,这将是很好的加密/解密密钥)

  2. 使用比特数组(我不知道该怎么做,但我认为这将是编译器相关)

你会怎么做?

推荐答案

如果您有兴趣密码,然后点击所有必须是正确的。无论你花几个月编写和测试测试和测试...自己大的数字运算功能,或者你使用现有的库。

If you are interested in Cryptography, then everything has to be correct. Either you spend many months writing and testing and testing and testing... your own big number arithmetic functions, or you use an existing library.

这是很难得到足够的密码才能正常工作,当你知道你正在使用的方法是正确的。如果您使用的方法有细微的错误,这几乎是不可能的。

It is difficult enough getting crypto to work correctly when you know that the methods you are using are correct. It is almost impossible if the methods you are using have subtle errors.

有关加密使用GMP,并专注于加密。

For crypto use GMP, and concentrate on the crypto.

如果你想编写自己的大量运算包,然后通过各种手段这样做。我也做了同样的自己,这是一个有趣和有益的经验。但不要用你自己的工作,为任何事情的关键。

If you want to write your own large number arithmetic package, then by all means do so. I have done the same myself and it is an interesting and useful experience. But don't use your own work for anything critical.

这篇关于如何处理用C大整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆