C++ Program to Perform Message Encoding Using Matrix Multiplication

This is a C++ Program to perform encoding matrix using a hidden-key. Encoding is performed using matrix multiplication between given matrix and key matrix.

Here is source code of the C++ Program to Perform Encoding of a Message Using Matrix Multiplication. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. #include<conio.h>
  2. #include<iostream>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a[10][10], b[10][10], c[10][10];
  7.     int x, y, i, j;
  8.  
  9.     cout << "\nEnter the number of rows and columns for Message Matrix:\n\n";
  10.     cin >> x >> y;
  11.  
  12.     // x denotes number rows in matrix A
  13.     // y denotes number columns in matrix A
  14.     cout << "\n\nEnter elements for Matrix :::\n\n";
  15.     for (i = 0; i < x; i++)
  16.     {
  17.         for (j = 0; j < y; j++)
  18.         {
  19.             cin >> a[i][j];
  20.         }
  21.         cout << "\n";
  22.     }
  23.     cout << "\n\nMatrix :\n\n";
  24.     for (i = 0; i < x; i++)
  25.     {
  26.         for (j = 0; j < y; j++)
  27.         {
  28.             cout << "\t" << a[i][j];
  29.         }
  30.         cout << "\n\n";
  31.     }
  32.  
  33.  
  34.  
  35.     for (i = 0; i < y; i++)
  36.     {
  37.         for (j = 0; j < x; j++)
  38.         {
  39.             b[i][j]=x+y;
  40.         }
  41.         cout << "\n";
  42.     }
  43.  
  44.         for (i = 0; i < x; i++)
  45.         {
  46.             for (j = 0; j < x; j++)
  47.             {
  48.                 c[i][j] = 0;
  49.                 for (int k = 0; k < y; k++)
  50.                 {
  51.                     c[i][j] = c[i][j] + a[i][k] * b[k][j];
  52.                 }
  53.             }
  54.         }
  55.         cout
  56.                 << "\n-----------------------------------------------------------\n";
  57.         cout << "\n\nEncoded Matrix :\n\n";
  58.         for (i = 0; i < x; i++)
  59.         {
  60.             for (j = 0; j < x; j++)
  61.             {
  62.                 cout << "\t" << c[i][j];
  63.             }
  64.             cout << "\n\n";
  65.         }
  66.     getch();
  67.     return 0;
  68. }

Output:

$ g++ EncodingMatrix.cpp
$ a.out
 
Enter the number of rows and columns for Message Matrix:
2 2
 
Enter elements for Matrix :::
1 2 
3 4
Matrix :
	1	2
	3	4
-----------------------------------------------------------
Encoded Matrix :
	12	12
	28	28

Sanfoundry Global Education & Learning Series – 1000 C++ Programs.

advertisement
advertisement

Here’s the list of Best Books in C++ Programming, Data Structures and Algorithms.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.