如何将字符串转换为ZZ数字? [英] How can i convert a string into a ZZ number?

查看:195
本文介绍了如何将字符串转换为ZZ数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using the NTL library to implement ElGamal encryption/decryption algorithm. I've got it to the point that it's working but the algorithm wants the message to be converted to integers so it can be encrypted.
So if i input a number like 1234 everything works ok but how would i go to be able to convert a C++ string (std::string) to a ZZ number and then back from that ZZ number to a string?

LE :

ZZ这是一个代表大量数字的类.
例如:18287348238476283658234881728316274273671623781254124517353

ZZ it's a class that represent a large number.
Ex: 18287348238476283658234881728316274273671623781254124517353

因此,基本上我希望以"Hello World"为例,逐个字符运行char并获取char的ascii代码,因此得到一个数字:"72 101 108 108 111 32 87 111 114 108 100"
然后我需要将此数字转换回字符串"Hello World"

So basically i'm looking to take "Hello World" for example and run it char by char and get the ascii code of the chars so i'll get a number: "72 101 108 108 111 32 87 111 114 108 100"
And then i need to convert this number back to string "Hello World"

或者也许有更好的方法.

Or maybe there's a better way.

推荐答案

这是一种简单的方法:

std::string str("1234567890");
NTL::ZZ number(NTL::INIT_VAL, str.c_str());

现在注意:

std::cout << str << std::endl; // prints 1234567890
std::cout << number << std::endl; // prints 1234567890

这篇关于如何将字符串转换为ZZ数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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