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 it's a class that represent a large number.
Ex: 18287348238476283658234881728316274273671623781254124517353
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.
Here is an easy way to do it:
Now notice that:
By far the easiest solution is to realize that you can convert
char
s tounsigned int
s, andunsigned int
s toZZ
numbers. Then treat the string as a base-256 number. For instance, "abc" would be 256*"ab" + "c", or 65536 * "a" + 256 * "b" + "c", or((ZZ(unsigned('a')*256) + ZZ(unsigned('b'))*256) + ZZ(unsigned('c'))
,Here is an answer from the NTL author's website:
Source: http://www.shoup.net/ntl/doc/conversions.txt
I tried it, and it worked perfectly.