# Path: parser/parsesolveroutput.py
# def getCharBoolectorOutput(output, cipher, rounds):
# def getCharSTPOutput(output, cipher, rounds):
# 
# Path: config.py
# PATH_STP = "../stp/build/stp"
# 
# PATH_BOOLECTOR = "../boolector/build/bin/boolector"
# 
# PATH_CRYPTOMINISAT = "../cryptominisat/build/cryptominisat5"
# 
# MAX_WEIGHT = 1000
# 
# MAX_CHARACTERISTICS = 10000000


from parser import parsesolveroutput
from config import (PATH_STP, PATH_BOOLECTOR, PATH_CRYPTOMINISAT, MAX_WEIGHT,
                    MAX_CHARACTERISTICS)
from fractions import gcd
import subprocess
import random
import math
import os
import time
    """
    with open(logfile_path, "r") as logfile:
        logged_solutions = 0
        for line in logfile:
            if "s SATISFIABLE" in line:
                logged_solutions += 1
        return logged_solutions
    return -1

def startSATsolver(stp_file):
    """
    Return CryptoMiniSat process started with the given stp_file.
    """
    # Start STP to construct CNF
    subprocess.check_output([PATH_STP, "--exit-after-CNF", "--output-CNF",
                             stp_file, "--CVC", "--disable-simplifications"])

    # Find the number of solutions with the SAT solver
    sat_params = [PATH_CRYPTOMINISAT, "--maxsol", str(MAX_CHARACTERISTICS),
                  "--verb", "0", "-s", "0", "output_0.cnf"]

    sat_process = subprocess.Popen(sat_params, stderr=subprocess.PIPE,
                                   stdout=subprocess.PIPE)

    return sat_process

def solveSTP(stp_file):
    """
    Returns the solution for the given SMT problem using STP.
    """

# Path: parser/parsesolveroutput.py
# def getCharBoolectorOutput(output, cipher, rounds):
# def getCharSTPOutput(output, cipher, rounds):
# 
# Path: config.py
# PATH_STP = "../stp/build/stp"
# 
# PATH_BOOLECTOR = "../boolector/build/bin/boolector"
# 
# PATH_CRYPTOMINISAT = "../cryptominisat/build/cryptominisat5"
# 
# MAX_WEIGHT = 1000
# 
# MAX_CHARACTERISTICS = 10000000


# Path: cryptanalysis/search.py
from parser import parsesolveroutput
from config import (PATH_STP, PATH_BOOLECTOR, PATH_CRYPTOMINISAT, MAX_WEIGHT,
                    MAX_CHARACTERISTICS)
from fractions import gcd
import subprocess
import random
import math
import os
import time

    """
    with open(logfile_path, "r") as logfile:
        logged_solutions = 0
        for line in logfile:
            if "s SATISFIABLE" in line:
                logged_solutions += 1
        return logged_solutions
    return -1

def startSATsolver(stp_file):
    """
    Return CryptoMiniSat process started with the given stp_file.
    """
    # Start STP to construct CNF
    subprocess.check_output([PATH_STP, "--exit-after-CNF", "--output-CNF",
                             stp_file, "--CVC", "--disable-simplifications"])

    # Find the number of solutions with the SAT solver
    sat_params = [PATH_CRYPTOMINISAT, "--maxsol", str(MAX_CHARACTERISTICS),
                  "--verb", "0", "-s", "0", "output_0.cnf"]

    sat_process = subprocess.Popen(sat_params, stderr=subprocess.PIPE,
                                   stdout=subprocess.PIPE)

    return sat_process

def solveSTP(stp_file):
    """
    Returns the solution for the given SMT problem using STP.
    """

    stp_parameters = [PATH_STP, stp_file, "--CVC"]