Reputation: 1835
Working on a college project for simple matrix multiplication based encryption.
The project outline is such;
text file to matrix multiplied by encryption key matrix= Encrypted file.
Encrypted file to matrix multiplied by inverse of key matrix = Decrypted file.
But I want to go a bit further and be able to do any file (text, mp3, gif etc etc).
I have been researching for hours trying to solve this problem and am starting to get a little frustrated.
The best way (and only) I can think of is for the program to read raw binary and perform encryption on that.
So--> questions:
Can I extract raw binary from a file, put into matrix, perform matrix multiplication and (essentially) write back binary to file?
Also what is the viability of such a method on different computers and platforms? ( I am thinking that maybe if I convert from binary to int and on decryption convert back, it might change-- different size allocations on different computers etc?)
Also, I am welcome to opinion on better solutions
---> But the basic algorithm should be based on matrix multiplication.
My code:
int writetomatrix(int current_variable)
{
if (counter == 9){
counter=0;
b=0;
a=0;}
if (b==3) b=0;
if (a==3) {b++;
a=0;}
counter++;
B[a][b]=current_variable;
a++;
}
int main () {
int *buffer= new int[1];
ifstream input;
input.open ("input.txt",ios::in|ios::binary);
input.read ((char*)&buffer, 1);
writetomatrix(buffer);
}
The error I get:
initializing argument 1 of ‘int writetomatrix(int)’
Upvotes: 0
Views: 1303
Reputation: 23160
You can read the binary file using fread
to an array of char or of int. As long as byte order remains the same, you can read any file and write it back. You can do what you want with the bytes or words you read. You can use sizeof
to know the size of an int. On most platforms today it is 4 bytes.
Upvotes: 0