<commit_before><?php

session_start();

function __autoload($classname) {
    require_once('../classes/' . $classname . '.class.php');
}

/* Credits to elusive (http://stackoverflow.com/users/427328/elusive) */
function in_array_r($needle, $haystack, $strict = false) {
    foreach ($haystack as $item) {
        if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
            return true;
        }
    }
    return false;
}

if (isset($_POST)) {
    $stringToHash = $_POST['stringToHash'];
    $SESSION['stringToHash'] = $stringToHash;
    if (isset($_POST['saltCheckbox'])) {
        $salt = $_POST['salt'];
        $_SESSION['salt'] = $salt;
        if (isset($_POST['placeSaltAt'])) {
            if ($_POST['placeSaltAt'] == 'beginning') {
                echo $stringToHash = $salt . $stringToHash;
            }
            else if ($_POST['placeSaltAt'] == 'end') {
                $stringToHash .= $salt;
            }
        }
    }
    
    $algorithm = strtoupper($_POST['algorithm']);
    
    $hashObj = new Hash();
    $mdArray = $hashObj->getMDArray();
    $ripemdArray = $hashObj->getRIPEMDArray();
    $shaArray = $hashObj->getSHAArray();
    
    $allArrays = $hashObj->getAllArrays();
    
    if (in_array_r($algorithm, $allArrays)) {
        if (in_array($algorithm, $mdArray)) {
            $hashFamily = new HashMD();
            switch ($algorithm) {
                case "MD5":
                    $hash = $hashFamily->getMD5Hash($stringToHash);
                    break;
            }
        }

        if (in_array($algorithm, $ripemdArray)) {
            $hashFamily = new HashRIPEMD();
            switch ($algorithm) {
                case "RIPEMD128":
                    $hash = $hashFamily->getRIPEMD128Hash($stringToHash);
                    break;
                case "RIPEMD160":
                    $hash = $hashFamily->getRIPEMD160Hash($stringToHash);
                    break;
                case "RIPEMD256":
                    $hash = $hashFamily->getRIPEMD256Hash($stringToHash);
                    break;
                case "RIPEMD320":
                    $hash = $hashFamily->getRIPEMD320Hash($stringToHash);
                    break;
            }
        }

        if (in_array($algorithm, $shaArray)) {
            $hashFamily = new HashSHA();
            switch ($algorithm) {
                case "SHA1":
                    $hash = $hashFamily->getSHA1Hash($stringToHash);
                    break;
                case "SHA256":
                    $hash = $hashFamily->getSHA256Hash($stringToHash);
                    break;
                case "SHA384":
                    $hash = $hashFamily->getSHA384Hash($stringToHash);
                    break;
                case "SHA512":
                    $hash = $hashFamily->getSHA512Hash($stringToHash);
                    break;
            }
        }
        
        $_SESSION['hash'] = $hash;
        
        header('Location: ' . $_SERVER['HTTP_REFERER']);
    } else {
        die("Algorithm doesn't exist");
    }
}
else {
    die("Unallowed access method");
}<commit_msg>Added sanitizing<commit_after><?php

session_start();

function __autoload($classname) {
    require_once('../classes/' . $classname . '.class.php');
}

/* Credits to elusive (http://stackoverflow.com/users/427328/elusive) */
function in_array_r($needle, $haystack, $strict = false) {
    foreach ($haystack as $item) {
        if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
            return true;
        }
    }
    return false;
}

$stringToHash = filter_input(INPUT_POST, 'stringToHash', FILTER_SANITIZE_STRING);
if (isset($stringToHash)) {
    $SESSION['stringToHash'] = $stringToHash;
    $saltCheckbox = filter_input(INPUT_POST, 'saltCheckbox', FILTER_SANITIZE_STRING);
    if (isset($saltCheckbox)) {
        $salt = filter_input(INPUT_POST, 'salt', FILTER_SANITIZE_STRING);
        $_SESSION['salt'] = $salt;
        $placeSaltAt = filter_input(INPUT_POST, 'placeSaltAt', FILTER_SANITIZE_STRING);
        if (isset($placeSaltAt)) {
            if ($placeSaltAt == 'beginning') {
                echo $stringToHash = $salt . $stringToHash;
            }
            else if ($placeSaltAt == 'end') {
                $stringToHash .= $salt;
            }
        }
    }
    
    $algorithm = strtoupper(filter_input(INPUT_POST, 'algorithm', FILTER_SANITIZE_STRING));
    
    $hashObj = new Hash();
    $mdArray = $hashObj->getMDArray();
    $ripemdArray = $hashObj->getRIPEMDArray();
    $shaArray = $hashObj->getSHAArray();
    
    $allArrays = $hashObj->getAllArrays();
    
    if (in_array_r($algorithm, $allArrays)) {
        if (in_array($algorithm, $mdArray)) {
            $hashFamily = new HashMD();
            switch ($algorithm) {
                case "MD5":
                    $hash = $hashFamily->getMD5Hash($stringToHash);
                    break;
            }
        }

        if (in_array($algorithm, $ripemdArray)) {
            $hashFamily = new HashRIPEMD();
            switch ($algorithm) {
                case "RIPEMD128":
                    $hash = $hashFamily->getRIPEMD128Hash($stringToHash);
                    break;
                case "RIPEMD160":
                    $hash = $hashFamily->getRIPEMD160Hash($stringToHash);
                    break;
                case "RIPEMD256":
                    $hash = $hashFamily->getRIPEMD256Hash($stringToHash);
                    break;
                case "RIPEMD320":
                    $hash = $hashFamily->getRIPEMD320Hash($stringToHash);
                    break;
            }
        }

        if (in_array($algorithm, $shaArray)) {
            $hashFamily = new HashSHA();
            switch ($algorithm) {
                case "SHA1":
                    $hash = $hashFamily->getSHA1Hash($stringToHash);
                    break;
                case "SHA256":
                    $hash = $hashFamily->getSHA256Hash($stringToHash);
                    break;
                case "SHA384":
                    $hash = $hashFamily->getSHA384Hash($stringToHash);
                    break;
                case "SHA512":
                    $hash = $hashFamily->getSHA512Hash($stringToHash);
                    break;
            }
        }
        
        $_SESSION['hash'] = $hash;
        
        header('Location: ' . filter_input(INPUT_SERVER, 'HTTP_REFERER', FILTER_SANITIZE_STRING));
    } else {
        die("Algorithm doesn't exist");
    }
}
else {
    die("Unallowed access method");
}
{'fraction_non_alphanumeric': 0.13838748495788206, 'fraction_numerical': 0.015643802647412757, 'mean_word_length': 1.725, 'pattern_counts': {'":': 18, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6626903', 'n_tokens_mistral': 2076, 'n_tokens_neox': 1933, 'n_words': 333}