Verifying the Output

In this article we continue our quick start series. We assume that you are following from the previous article.

8. Deserialize and Display the Result

We will deserialize the decrypted tensor and output the result.

    // Deserialize the plaintext tensor
    Tensor<CPUCryptoSystem::PlainText*> result_tensor = cs.deserialize_plaintext_tensor(res->data());

    // Flatten the tensor for easy traversal
    result_tensor.flatten();

    // Display the result
    std::cout << "Resulting matrix after multiplication and decryption:" << std::endl;
    for (size_t idx = 0; idx < result_tensor.size(); ++idx) {
        float value = cs.get_float_from_plaintext(*result_tensor[idx]);
        std::cout << value << " ";
        if ((idx + 1) % p == 0) {
            std::cout << std::endl;
        }
    }

    // Calculate and display computation times
    auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
    auto duration_d = std::chrono::duration_cast<std::chrono::microseconds>(stop_d - stop);

    std::cout << "Time taken by multiplication: " << duration.count() << " microseconds" << std::endl;
    std::cout << "Time taken by decryption: " << duration_d.count() << " microseconds" << std::endl;

    return 0;
}

Explanation:

  • We deserialize the plaintext tensor from the response data.

  • Flattening the tensor allows us to traverse all elements easily.

  • We use get_float_from_plaintext to extract float values from the plaintexts.

  • The results are displayed in matrix form.

  • We output the durations for both multiplication and decryption.

Last updated