// Path: src/main/java/com/tiemens/secretshare/exceptions/SecretShareException.java
// public class SecretShareException
//     extends RuntimeException
// {
//     // ==================================================
//     // class static data
//     // ==================================================
// 
//     private static final long serialVersionUID = 2193317873773384997L;
// 
//     // ==================================================
//     // class static methods
//     // ==================================================
// 
// 
// 
//     // ==================================================
//     // instance data
//     // ==================================================
// 
//     // ==================================================
//     // factories
//     // ==================================================
// 
//     // ==================================================
//     // constructors
//     // ==================================================
// 
// 
//     /** Constructs a new runtime exception with the specified detail message.
//      * The cause is not initialized, and may subsequently be initialized by a
//      * call to {@link #initCause}.
//      *
//      * @param   message   the detail message. The detail message is saved for
//      *          later retrieval by the {@link #getMessage()} method.
//      */
//     public SecretShareException(final String message)
//     {
//         super(message);
//     }
// 
//     /**
//      * Constructs a new runtime exception with the specified detail message and
//      * cause.  <p>Note that the detail message associated with
//      * <code>cause</code> is <i>not</i> automatically incorporated in
//      * this runtime exception's detail message.
//      *
//      * @param  message the detail message (which is saved for later retrieval
//      *         by the {@link #getMessage()} method).
//      * @param  cause the cause (which is saved for later retrieval by the
//      *         {@link #getCause()} method).  (A <code>null</code> value is
//      *         permitted, and indicates that the cause is nonexistent or
//      *         unknown.)
//      */
//     public SecretShareException(final String message,
//                                 final Throwable cause)
//     {
//         super(message, cause);
//     }
// 
//     // ==================================================
//     // public methods
//     // ==================================================
// 
//     // ==================================================
//     // non public methods
//     // ==================================================
// }


import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.security.SecureRandom;
import java.util.Random;
import com.tiemens.secretshare.exceptions.SecretShareException;
/*******************************************************************************
 * Copyright (c) 2009, 2014 Tim Tiemens.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 *
 * Contributors:
 *     Tim Tiemens - initial API and implementation
 *******************************************************************************/
package com.tiemens.secretshare.math.type;



public final class BigIntUtilities
{


    // ==================================================
    // class static data
    // ==================================================
    private static final String UTF8 = "UTF-8";

    // ==================================================
    // class static methods
    // ==================================================

    /**
     * Converter class   : "Human"
     * Input format      : Any (human readable) string
     * Example input     : "This is my cat"
     *  gives BigInteger : 1711994770713785234966317640147316
     */
    public static class Human
    {
        /**
         * Convert a "human string" into a BigInteger by using the string's
         *   byte[] array.
         * This is NOT EVEN CLOSE to the same as new BigInteger("string").
         *
         * @param in a string like "This is my cat" or "123FooBar"
         * @return BigInteger
         * @throws SecretShareException on error
         */
        public static BigInteger createBigInteger(final String in)
        {
            BigInteger ret = null;
            try
            {
                byte[] b = in.getBytes(UTF8);
                ret = new BigInteger(b);
                return ret;
            }
            catch (UnsupportedEncodingException e)
            {
                // just can't happen, but if it does:
// Path: src/main/java/com/tiemens/secretshare/exceptions/SecretShareException.java
// public class SecretShareException
//     extends RuntimeException
// {
//     // ==================================================
//     // class static data
//     // ==================================================
// 
//     private static final long serialVersionUID = 2193317873773384997L;
// 
//     // ==================================================
//     // class static methods
//     // ==================================================
// 
// 
// 
//     // ==================================================
//     // instance data
//     // ==================================================
// 
//     // ==================================================
//     // factories
//     // ==================================================
// 
//     // ==================================================
//     // constructors
//     // ==================================================
// 
// 
//     /** Constructs a new runtime exception with the specified detail message.
//      * The cause is not initialized, and may subsequently be initialized by a
//      * call to {@link #initCause}.
//      *
//      * @param   message   the detail message. The detail message is saved for
//      *          later retrieval by the {@link #getMessage()} method.
//      */
//     public SecretShareException(final String message)
//     {
//         super(message);
//     }
// 
//     /**
//      * Constructs a new runtime exception with the specified detail message and
//      * cause.  <p>Note that the detail message associated with
//      * <code>cause</code> is <i>not</i> automatically incorporated in
//      * this runtime exception's detail message.
//      *
//      * @param  message the detail message (which is saved for later retrieval
//      *         by the {@link #getMessage()} method).
//      * @param  cause the cause (which is saved for later retrieval by the
//      *         {@link #getCause()} method).  (A <code>null</code> value is
//      *         permitted, and indicates that the cause is nonexistent or
//      *         unknown.)
//      */
//     public SecretShareException(final String message,
//                                 final Throwable cause)
//     {
//         super(message, cause);
//     }
// 
//     // ==================================================
//     // public methods
//     // ==================================================
// 
//     // ==================================================
//     // non public methods
//     // ==================================================
// }


// Path: src/main/java/com/tiemens/secretshare/math/type/BigIntUtilities.java
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.security.SecureRandom;
import java.util.Random;
import com.tiemens.secretshare.exceptions.SecretShareException;

/*******************************************************************************
 * Copyright (c) 2009, 2014 Tim Tiemens.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 *
 * Contributors:
 *     Tim Tiemens - initial API and implementation
 *******************************************************************************/
package com.tiemens.secretshare.math.type;



public final class BigIntUtilities
{


    // ==================================================
    // class static data
    // ==================================================
    private static final String UTF8 = "UTF-8";

    // ==================================================
    // class static methods
    // ==================================================

    /**
     * Converter class   : "Human"
     * Input format      : Any (human readable) string
     * Example input     : "This is my cat"
     *  gives BigInteger : 1711994770713785234966317640147316
     */
    public static class Human
    {
        /**
         * Convert a "human string" into a BigInteger by using the string's
         *   byte[] array.
         * This is NOT EVEN CLOSE to the same as new BigInteger("string").
         *
         * @param in a string like "This is my cat" or "123FooBar"
         * @return BigInteger
         * @throws SecretShareException on error
         */
        public static BigInteger createBigInteger(final String in)
        {
            BigInteger ret = null;
            try
            {
                byte[] b = in.getBytes(UTF8);
                ret = new BigInteger(b);
                return ret;
            }
            catch (UnsupportedEncodingException e)
            {
                // just can't happen, but if it does:
                throw new SecretShareException("UTF8 not found", e);