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.
#include<conio.h>
#include<iostream>
using namespace std;
int main()
{
int a[10][10], b[10][10], c[10][10];
int x, y, i, j;
cout << "\nEnter the number of rows and columns for Message Matrix:\n\n";
cin >> x >> y;
// x denotes number rows in matrix A
// y denotes number columns in matrix A
cout << "\n\nEnter elements for Matrix :::\n\n";
for (i = 0; i < x; i++)
{
for (j = 0; j < y; j++)
{
cin >> a[i][j];
}
cout << "\n";
}
cout << "\n\nMatrix :\n\n";
for (i = 0; i < x; i++)
{
for (j = 0; j < y; j++)
{
cout << "\t" << a[i][j];
}
cout << "\n\n";
}
for (i = 0; i < y; i++)
{
for (j = 0; j < x; j++)
{
b[i][j]=x+y;
}
cout << "\n";
}
for (i = 0; i < x; i++)
{
for (j = 0; j < x; j++)
{
c[i][j] = 0;
for (int k = 0; k < y; k++)
{
c[i][j] = c[i][j] + a[i][k] * b[k][j];
}
}
}
cout
<< "\n-----------------------------------------------------------\n";
cout << "\n\nEncoded Matrix :\n\n";
for (i = 0; i < x; i++)
{
for (j = 0; j < x; j++)
{
cout << "\t" << c[i][j];
}
cout << "\n\n";
}
getch();
return 0;
}
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]Related Posts:
- Apply for C++ Internship
- Practice Programming MCQs
- Check Programming Books
- Check C++ Books
- Apply for Computer Science Internship