<commit_before><?php

namespace Abelorosz\Twostep;

class Twostep {

	private static $PASS_CODE_LENGTH = 6;
    private static $PIN_MODULO;
    private static $SECRET_LENGTH = 10;

	public function __construct()
	{
        self::$PIN_MODULO = pow(10, self::$PASS_CODE_LENGTH);
    }

    /**
     * Check the given code
     *
     * @param 	int $code
     * @param 	string $secret
     * @return 	bool
     */
    public function checkCode( $code, $secret )
    {
        $time = floor(time() / 30);
        for ( $i = -1; $i <= 1; $i++ )
            if ($this->getCode($secret,$time + $i) == $code)
                return true;
        
        return false;
    }
    
    /**
     * Get the url of a QR code
     *
     * @param 	string $user
     * @param 	string $hostname
     * @param 	string $secret
     * @return 	string
     */
    public function getUrl( $user, $hostname, $secret )
    {
        $url = sprintf("otpauth://totp/%s@%s?secret=%s", $user, $hostname, $secret);
        $encoder = "https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=";
        $encoderURL = sprintf("%sotpauth://totp/%s@%s?secret=%s",$encoder, $user, $hostname, $secret);
        
        return $encoderURL;
    }
    
    /**
     * Generate a secret code
     *
     * @return 	string
     */
    public function generateSecret()
    {
        $secret = "";
        for($i = 1;  $i<= self::$SECRET_LENGTH;$i++) {
            $c = rand(0,255);
            $secret .= pack("c",$c);
        }
        $base32 = new FixedBitNotation(5, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567', TRUE, TRUE);
        
        return  $base32->encode($secret);
    }

    /**
     * Generate a code (for a given time)
     *
     * @param 	string $secret
     * @param 	timestamp $time
     * @return 	int
     */
    public function getCode( $secret, $time = null )
    {   <commit_msg>Update Twostep.php<commit_after><?php

namespace Abelorosz\Twostep;

class Twostep {

	private static $PASS_CODE_LENGTH = 6;
    private static $PIN_MODULO;
    private static $SECRET_LENGTH = 10;

	public function __construct()
	{
        self::$PIN_MODULO = pow(10, self::$PASS_CODE_LENGTH);
    }

    /**
     * Check the given code
     *
     * @param 	int $code
     * @param 	string $secret
     * @return 	bool
     */
    public function checkCode( $code, $secret )
    {
        $time = floor(time() / 30);
        for ( $i = -1; $i <= 1; $i++ )
            if ($this->getCode($secret,$time + $i) == $code)
                return true;
        
        return false;
    }
    
    /**
     * Get the url of a QR code
     *
     * @param 	string $user
     * @param 	string $hostname
     * @param 	string $secret
     * @return 	string
     */
    public function getUrl( $user, $hostname, $secret )
    {
        $url = sprintf("otpauth://totp/%s@%s?secret=%s", $user, $hostname, $secret);
        $encoder = "https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl=";
        $encoderURL = sprintf("%sotpauth://totp/%s@%s?secret=%s",$encoder, $user, $hostname, $secret);
        
        return $encoderURL;
    }
    
    /**
     * Generate a secret code
     *
     * @return 	string
     */
    public function generateSecret()
    {
        $secret = "";
        for($i = 1;  $i<= self::$SECRET_LENGTH;$i++) {
            $c = rand(0,255);
            $secret .= pack("c",$c);
        }
        $base32 = new FixedBitNotation(5, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567', TRUE, TRUE);
        
        return  $base32->encode($secret);
    }

    /**
     * Generate a code (for a given time)
     *
     * @param 	string $secret
     * @param 	timestamp $time
     * @return 	int
     */
    public function getCode( $secret, $time = null )
    {   
{'fraction_non_alphanumeric': 0.15065560610115067, 'fraction_numerical': 0.017126036928017126, 'mean_word_length': 1.9456264775413712, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, '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': '7299805', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1297, 'n_words': 283}