Boost logo

Boost Users :

From: chun ping wang (cablepuff_at_[hidden])
Date: 2007-10-31 13:33:55


HI how would I use program options to accept multiple input.

Example I have a diffieHellmanKeyExchange program running through command
prompt.

// begin main program
#include <iostream>
#include <boost/tuple/tuple_io.hpp>
#include <boost/program_options.hpp>
#include "cppdef/BitOperation.cpp"
#include "cppdef/mathfunc.cpp"
#include "cppdef/IsPrime.cpp"
#include "cppdef/DiffieHellman.cpp"
#include <BigInteger.hpp>
#include <BigIntegerUtils.hpp>

int main( int ac, char* av[] )
{
    namespace po = boost::program_options;
    po::options_description desc("Allowed options");
    boost::tuple<BigInteger, BigInteger> key_pair;
    desc.add_options()
        ("generate", "generates a pair of key")
        ("secert", po::value(&key_pair), "creates the share secret key");

    po::variables_map vm;
    po::store(po::parse_command_line(ac, av, desc), vm);
    po::notify(vm);

    if (vm.count("generate"))
    {
        BigInteger my_prime =
encryptcpw::random_prime<BigInteger>(&algocpw::Miller_Rabin<BigInteger>,
10);
        std::cout << "my prime: " << my_prime << "\n";
        boost::tuple<BigInteger, BigInteger>
pare(encryptcpw::dh_init<BigInteger>(
             my_prime
        ));
        std::cout << "pair of generated number: " << pare << "\n";
    }
    if (vm.count("secert"))
    {
        const BigInteger p(
encryptcpw::random_prime<BigInteger>(&algocpw::Miller_Rabin<BigInteger>,
10));
        std::cout << encryptcpw::dh_secret<BigInteger>(
                         p,
                         boost::tuples::get<0>(key_pair),
                          boost::tuples::get<1>(key_pair));
    }
}

// end program

The thing compiles but when I do DiffieHellman.exe --secert 817 697

I get this error.
C:\CPW\cs_classes>DiffieHellmanEncrypt --secert 817 697
terminate called after throwing an instance of
'boost::program_options::invalid_
option_value'
  what(): in option 'secert': invalid option value '817'

This application has requested the Runtime to terminate it in an unusual
way.
Please contact the application's support team for more information.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net