public function validateCode($code, $initKey = null, $timestamp = null, $range = null)
    {
        if (strlen($code) !== $this->getCodeLength()) {
            throw new \InvalidArgumentException('Incorrect code length');
        }

        $range = ($range == null) ? $this->getRange() : $range;
        $timestamp = ($timestamp == null) ? $this->generateTimestamp() : $timestamp;
        $initKey = ($initKey == null) ? $this->getInitKey() : $initKey;

        $binary = $this->base32_decode($initKey);

        for ($time = ($timestamp - $range); $time <= ($timestamp + $range); $time++) {
            if ($this->generateOneTime($binary, $time) == $code) {
                return true;
            }
        }
        return false;
    }