Repository: TheAlgorithms/C-Plus-Plus
File: hashing/sha256.cpp (C++)

Code before:
            c = b;
            b = a;
            a = temp1 + temp2;
        }

        // Update hash values
        hash[0] += a;
        hash[1] += b;
        hash[2] += c;
        hash[3] += d;
        hash[4] += e;
        hash[5] += f;
        hash[6] += g;
        hash[7] += h;
    }

    // Convert the hash to a hexadecimal string
    std::string result;
    for (size_t i = 0; i < 8; ++i) {
        for (size_t j = 0; j < 4; ++j) {
            uint32_t byte = (hash[i] >> (24 - j * 8)) & 0xFF;
            std::stringstream ss;
            ss << std::hex << std::setfill('0') << std::setw(2) << byte;
            result += ss.str();
        }
    }

    return result;
}
}  // namespace sha256
}  // namespace hashing

/**
 * @brief Self-test implementations
 * @returns void
 */
static void test() {
    // 1st Test
    std::string input = "";
    std::string expected =
        "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
    std::string output = hashing::sha256::sha256(input);
    std::cout << "Input: " << input << std::endl;
    std::cout << "Expected: " << expected << std::endl;
    std::cout << "Output: " << output << std::endl;
    assert(output == expected);
    std::cout << "1st TEST PASSED\n\n";

    // 2nd Test
    input = "test";
    expected =

Review comment (refactor):
What do you think about abstracting this into some function of the form
```cpp
std::string hash_to_string(const std::array<uint32_t, 8>& hash);
```

Code after:
        return input_size + 64 - (input_size % 64);
    }
    return input_size + 128 - (input_size % 64);
}

/**
 * @brief Returns the byte at position byte_num in in_value
 * @param in_value Input value
 * @param byte_num Position of byte to be returned
 * @return uint8_t Byte at position byte_num
 */
template <typename T>
uint8_t extract_byte(const T in_value, const std::size_t byte_num) {
    if (sizeof(in_value) <= byte_num) {
        throw std::out_of_range("Byte at index byte_num does not exist");
    }
    return (in_value >> (byte_num * 8)) & 0xFF;
}

/**
 * @brief Returns the character at pos after the input is padded
 * @param input Input string
 * @param pos Position of character to be returned
 * @return char Character at the index pos in the padded string
 */
char get_char(const std::string &input, std::size_t pos) {
    const auto input_size = input.length();
    if (pos < input_size) {
        return input[pos];
    }
    if (pos == input_size) {
        return '\x80';
    }
    const auto padded_input_size = compute_padded_size(input_size);
    if (pos < padded_input_size - 8) {
        return '\x00';
    }
    if (padded_input_size <= pos) {
        throw std::out_of_range("pos is out of range");
    }
    return static_cast<char>(
        extract_byte<size_t>(input_size * 8, padded_input_size - pos - 1));
}

/**
 * @brief Creates the message schedule array
 * @param input Input string
 * @param byte_num Position of the first byte of the chunk
 * @return std::array<uint32_t, 64> Message schedule array
 */
std::array<uint32_t, 64> create_message_schedule_array(const std::string &input,