unserialize Integer type (cryptopp)

19 views
Skip to first unread message

Ahlem

unread,
May 25, 2019, 8:34:41 PM5/25/19
to Crypto++ Users
i use this   unserialize  
char c;
   Integer m_n;
   m_n=Integer(c);
it's correct please help

mohamed

unread,
May 30, 2019, 6:45:01 AM5/30/19
to Crypto++ Users
serialization de Integer (cryptopp) in ns3

    std::ostringstream oss;
    oss << m_n;

    std::string s = oss.str();
    //std::cout << s << std::endl;
   // serialisation
  int x;
  int len=s.length();
  uint8_t l= (uint8_t) len;
  //   std::cout <<"h serialize"<< h<< std::endl;
//  cout<< "len serialz "<<len<<"  \n"<<endl;
  i.WriteU8 (l);  //insérer la longueur de la chaine pour l'utiliser dans la déserialisation
   for (int j = 0; j < len;  j++)
    {
        x= (int) s[j];
uint8_t y = (uint8_t) x;
i.WriteU8 (y);
    }



unserialization of Integer (cryptopp) in ns3
 uint8_t l = i.ReadU8 ();  //récupérer la longueur
  double gg= (double) l;
int len = ( int ) gg;
//cout<< "len deserialz "<<len<<"  \n"<<endl;
len=310;
// cout<< "len serialz "<<len<<"  \n"<<endl;
std::istringstream iss;
string s="";
//construction du string
 for (int j = 0; j < len;  j++)
   {
        uint8_t ci = i.ReadU8();
int cii = (int) ci;
char c = char(cii);
//cout<< "le caractère est :cc "<<c<<"  \n"<<endl;
s+=c;   //concaténer caractère par caractère pour récupérer toute la chaine
   }
const char*  cstr =  s.c_str() ;
//j'ai utiliser ce constructeur pour récupérer le Integer, Integer(const char *str)
Integer g = Integer(cstr);
m_n=g;




I found the solution I want to share it with you for


--
You received this message because you are subscribed to "Crypto++ Users". More information about Crypto++ and this group is available at http://www.cryptopp.com and http://groups.google.com/forum/#!forum/cryptopp-users.
---
You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cryptopp-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cryptopp-users/5070ad53-ec27-42b5-8198-6c9c296d9c1d%40googlegroups.com.

Jeffrey Walton

unread,
May 30, 2019, 11:47:47 AM5/30/19
to Crypto++ Users


On Thursday, May 30, 2019 at 6:45:01 AM UTC-4, Ahlem wrote:
...

unserialization of Integer (cryptopp) in ns3
 uint8_t l = i.ReadU8 ();  //récupérer la longueur
  double gg= (double) l;
int len = ( int ) gg;
//cout<< "len deserialz "<<len<<"  \n"<<endl;
len=310;
// cout<< "len serialz "<<len<<"  \n"<<endl;
std::istringstream iss;
string s="";
//construction du string
 for (int j = 0; j < len;  j++)
   {
        uint8_t ci = i.ReadU8();
int cii = (int) ci;
char c = char(cii);
//cout<< "le caractère est :cc "<<c<<"  \n"<<endl;
s+=c;   //concaténer caractère par caractère pour récupérer toute la chaine
   }
const char*  cstr =  s.c_str() ;
//j'ai utiliser ce constructeur pour récupérer le Integer, Integer(const char *str)
Integer g = Integer(cstr);
m_n=g;

This may be a little easier. It uses the string from the earlier oss.str(). No need to convert to a binary array. Leave it as an ASCII string.

    std::string x = "17a94c...2d63c8h";
    StringSource ss(x, true, new HexDecoder);
    Integer n(ss, ss.MaxRetrievable());

Jeff
Reply all
Reply to author
Forward
0 new messages