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

Code before:
/**
 * @brief Creates the message schedule array
 * @param input Input string
 * @param i Position of the first bit 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,
                                                       const size_t i) {
    std::array<uint32_t, 64> blocks{};

    // Copy chunk into first 16 words of the message schedule array
    for (size_t j = 0; j < 16; ++j) {
        blocks[j] =
            (static_cast<uint8_t>(get_char(input, i + j * 4)) << 24) |
            (static_cast<uint8_t>(get_char(input, i + j * 4 + 1)) << 16) |
            (static_cast<uint8_t>(get_char(input, i + j * 4 + 2)) << 8) |
            static_cast<uint8_t>(get_char(input, i + j * 4 + 3));
    }

    // Extend the first 16 words into remaining 48 words of the message schedule
    // array
    for (size_t j = 16; j < 64; ++j) {
        uint32_t s0 = right_rotate(blocks[j - 15], 7) ^
                      right_rotate(blocks[j - 15], 18) ^ (blocks[j - 15] >> 3);
        uint32_t s1 = right_rotate(blocks[j - 2], 17) ^
                      right_rotate(blocks[j - 2], 19) ^ (blocks[j - 2] >> 10);
        blocks[j] = blocks[j - 16] + s0 + blocks[j - 7] + s1;
    }

    return blocks;
}

/**
 * @brief Modifies the hash array
 * @param hash Hash array to be modified
 * @param blocks Message schedule array
 * @return void
 */
void modify_hash(std::array<uint32_t, 8> &hash,
                 const std::array<uint32_t, 64> &blocks) {
    // Initialize array of round constants with first 32 bits of the fractional
    // parts of the cube roots of the first 64 primes 2..311
    const std::array<uint32_t, 64> k = {
        0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1,
        0x923F82A4, 0xAB1C5ED5, 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
        0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, 0xE49B69C1, 0xEFBE4786,
        0x0FC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
        0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147,
        0x06CA6351, 0x14292967, 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
        0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, 0xA2BFE8A1, 0xA81A664B,
        0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,

Review comment (suggestion):
```suggestion
        const auto s0 = right_rotate(blocks[j - 15], 7) ^
                        right_rotate(blocks[j - 15], 18) ^
                        (blocks[j - 15] >> 3);
        const auto s1 = right_rotate(blocks[j - 2], 17) ^
                        right_rotate(blocks[j - 2], 19) ^ (blocks[j - 2] >> 10);
```

Code after:
        const auto s1 =
            right_rotate(e, 6) ^ right_rotate(e, 11) ^ right_rotate(e, 25);
        const auto ch = (e & f) ^ (~e & g);
        const auto temp1 =
            h + s1 + ch + round_constants[block_num] + blocks[block_num];
        const auto s0 =
            right_rotate(a, 2) ^ right_rotate(a, 13) ^ right_rotate(a, 22);
        const auto maj = (a & b) ^ (a & c) ^ (b & c);
        const auto temp2 = s0 + maj;

        h = g;
        g = f;
        f = e;
        e = d + temp1;
        d = c;
        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;
}

/**
 * @brief Convert the hash to a hexadecimal string
 * @return std::string Final hash value
 */
std::string Hash::to_string() const {
    std::stringstream ss;
    for (size_t i = 0; i < 8; ++i) {
        ss << std::hex << std::setfill('0') << std::setw(8) << hash[i];
    }
    return ss.str();
}

/**
 * @brief Computes size of the padded input
 * @param input Input string
 * @return size_t Size of the padded input
 */
std::size_t compute_padded_size(const std::size_t input_size) {
    if (input_size % 64 < 56) {
        return input_size + 64 - (input_size % 64);