Help with C program and multiplying matrices Okay, some background for what I am
ID: 3850511 • Letter: H
Question
Help with C program and multiplying matrices
Okay, some background for what I am trying to accomplish. I have a key matrix that needs to be multiplied with the numerical value of the matrix that stores the plaintext. I'm not even sure how to make a 2d matrix with characters stored in them
this is the code I have:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 10000
int main() {
FILE *keyFile = fopen("one.txt", "r");
FILE *inputFile = fopen("two.txt", "r");
int i=0;
int j=0;
int key[10][10];
int keySize;
char ch;
char plainText[MAX];
//scan key grid size
fscanf(keyFile,"%d", &keySize);
//print grid
printf("Key: ");
for(i=0; i<keySize;i++){
for(j=0;j<keySize; j++){
fscanf(keyFile,"%d", &key[i][j]);
printf("%d ", key[i][j]);
}
printf(" ");
}
//setting counters back to 0;
i=0;
j=0;
//ch intakes characters from file
//plaintext only prints lowercase characters
printf(" Plaintext: ");
while ((ch = fgetc(inputFile)) != EOF) {
if (ch>='a' && ch<='z') {
printf("%c",ch);
plainText[i]=ch;
i++;
}
}
fclose(inputFile);
fclose(keyFile);
return 0;
}
one.txt includes:
4
9 12 13 1
7 3 6 9
8 4 2 1
10 5 15 3
two.txt includes:
Security professionals have said for years that the only way to make a computer truly secure is for it to not be connected to any other computers, a method called airgapping. Then, any attack would have to happen physically, with the attacker actually entering the room and accessing the computer that way, which is incredibly unlikely. In the case of computers containing highly sensitive information, additional, physical security can always be added in the form of security guards, cameras, and so on.
Researchers at Georgia Institute of Technology have uncovered a vulnerability in all computers, however, which can be exploited regardless of an air gap. It’s a vulnerability which you’d never suspect, and it’s one that’s hard to fight against. All CPUs emit electromagnetic signals when they are performing tasks, and the first thing these researchers discovered was that binary ones and zeroes emit different levels. The second thing they discovered is that electromagnetic radiation is also emitted by the voltage fluctuations and that it can be read from up to six meters away. These signals, by the way, are known as side-channels, and they are well-documented in the cryptography field.
The output is:
wsceafwvgznsacsihctehylsayiyanlevvrznraqaimmhdcajbjnuqowykyivehgkiztslktzvtlhxbb
lehmcpoddwkbnrmwpszcognnoxhsujopvehggfgfunbegpydafnalyubtzumbaryxctoolpkueyssrjy
cdyhojobqftmdqgbdfftfpcmptrlqblscygqqqdxwtlikntstkzynvmmvpysnfggiyyorwarxoifrocr
rcncuxmfjhrdnuqlnmwfonkzfaqrzcsxurclysqewceqsrudvehgixiljruwhapsojuzfyktsnyjyhwl
vrkceovbtuqheptotuqheqeyygyqfrognudutffdcjkvhektblwuzixkijszqyjnwsceafwvzvpdjjwu
nqqfwxruffhfxpkedwbggfgfxpqkrduinkpehormclniilpmejihjohafckdfanspsnorbauspqbypan
fmxwfpgccdibgdcrdqevwnmtyvwhdyqzyiusrivktliuywsytxpbihilgmtlonudnaxuhkxypwnahkql
mtcpzdugihctxighzgbyyjitpujkqnitbwpwwrsvvvkqpzzllwxwapqpkwkocnmxnnkwrdrpgvwblrtl
ybybnynehxqikxelwhtopgejztqwwxruaplojwfyihbunvmmtqqztfvrperkihifvkobcjypcxngpfie
ytgpolihmwfdkrcjkwkoebdcgdqzyqymixqhncybvbdnqksubaryhimvzptvjahmwbzifyrgmprwqgkk
edkrrojkpigzojqpqhqdrxlrzqtytrakzkfizjlbuijltoypwlshrrfjnqhmgxrkgzedkeooqpribrpd
rmyvbhwowplkkiakbwktopebrmcntrjpbcipirmbpwerlwfqotefguzlhxqixnsmyuwscauakrjiomfj
tounfowfrmrauhyhppnt
Ignore the spacing. I'm also wanting to split the program up into functions. I'm not sure how to do that when it comes to input file pointers. Any help is appreciated. Thank you
Each letter is numbered from 0 to 25. A B C D E FI G HI JK IL IM IN O P IQ R S T LU V WW Y Z 0 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 2 2 2 1 2 3 4 5 6 7 8 0 2 3 4 5 The phrase to encode is: LINEAR ALGEBRA IS SO EASY Divide the phrase into batches ofthree letters and convert them into matrix form as shown below: 1 8 11 B 1 8 O 14 18 N 13 R 17 G 6 R 17 18 E 24 Key matrix is: 3 10 20 A 20 9 17 9 4 17Explanation / Answer
#include #include #include #include #define MAXSIZE 9 #define BUFFERMAX 10000 #define ROWLENGTH 80 #define ALPHABET 26 void usage(){ printf("USAGE: [PATH to KeyFile][PATH to inputFile]" ); return; } int main(int argc, char *argv[]){ //*****DECLARATION OF VARIABLES*****// FILE *fp, *keyFile; int numRowAndColumns, alphaBit, padding = 0; char fileBuffer[BUFFERMAX]; int encryptMatrix[MAXSIZE][MAXSIZE], cipherTextMatrix[MAXSIZE][1], messageMatrix[BUFFERMAX]; int i,j,k; //*****ZERO INITIALIZERS*****// int n = 0; int charCount = 0; int counter = 0; int total = 0; int sum = 0; if(argc != 3){ usage(); return 0; } //*****OPEN AND READ FILES [KeyFile]*****// keyFile = fopen(argv[1],"r"); if(keyFile == NULL){ printf("Key File Not Found! "); return 0; } //*****OPEN AND READ FILES [inputFile]*****// fp = fopen(argv[2],"r"); if(fp == NULL){ printf("Input File not found! "); return 0; } //******** READ KEYFILE **********/// fscanf(keyFile,"%d", &numRowAndColumns); while(!feof(keyFile)){ for(i=0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.