gpt4 book ai didi

c++ - 如何将字符串转换为 ZZ 数字?

转载 作者:行者123 更新时间:2023-11-30 01:32:07 25 4
gpt4 key购买 nike

我正在使用 NTL library实现 ElGamal 加密/解密算法。我已经知道它可以正常工作了,但是算法希望将消息转换为整数,以便对其进行加密。
因此,如果我输入像 1234 这样的数字,一切正常,但我如何才能将 C++ 字符串 (std::string) 转换为 ZZ 数字,然后从该 ZZ 数字返回到字符串?

LE:

ZZ是代表大数的类。
例如:18287348238476283658234881728316274273671623781254124517353

所以基本上我想以“Hello World”为例,逐个字符地运行它并获取字符的 ascii 代码,这样我就会得到一个数字:“72 101 108 108 111 32 87 111 114 108 100"
然后我需要将这个数字转换回字符串“Hello World”

或者也许有更好的方法。

最佳答案

这是来自 NTL 作者网站的答案:

In addition to the conversions listed, there is a generic conversion from a C-strings (i.e., const char *) to any type T, which is implemented using templates using the input operator >> for type T. So, for example, you can write

    ZZ x = conv<ZZ>("99999999999999999999999");

来源:http://www.shoup.net/ntl/doc/conversions.txt

我试过了,效果很好。

关于c++ - 如何将字符串转换为 ZZ 数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2117312/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com