Answered step by step
Verified Expert Solution
Question
1 Approved Answer
EncryptText function help. In this assignment you ll write a program that encrypts the alphabetic letters in a file using the Hill cipher where the
EncryptText function help. In this assignment youll write a program that encrypts the alphabetic letters in a file using the Hill cipher where the Hill matrix can be any size from xup to xYour program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. Encryption Key File Formats
The encryption key file will contain a single positive integer, n where n on the first
line, indicating the number of rows and columns in the encryption matrix. The following n lines
will contain n integers, in each row, in order, of the encryption matrix, separated by spaces.
Encryption Plaintext File Formats
The file to be encrypted can be any valid text file with no more than letters in itThus
its safe to store all characters in the file in a character array of size including any
padding characters.Please note that the input text file will also generally have punctuation,
numbers, special characters, and whitespace in itwhich should be ignored. You should also
convert uppercase letters to lowercase in the input file, correspondingly lowercase letters do
not need to be converted. Thus, the program will treat A and a the same in your program.
Remember that the input plaintext file may need to be padded to match the block size of the
key. #include
#include
#include
#define MAXFILESIZE
Function prototypes
void readKeyFilechar keyFileNameint matrixSizeint keyMatrix;
int readPlainTextFilechar plainTextFileNamechar plainText;
void encryptTextchar plainTextint matrixSize, int keyMatrix;
void outputCiphertextchar ciphertext;
int mainint argc, char argv
Check for correct number of command line arguments
if argc
printfUsage: s
argv;
return ;
Parse command line arguments
char keyFileName argv;
char plainTextFileName argv;
Variables for key matrix and size
int matrixSize;
int keyMatrix;
Read encryption key file
readKeyFilekeyFileName&matrixSize, keyMatrix;
Read plaintext file
char plainTextMAXFILESIZE;
int numLetters readPlainTextFileplainTextFileNameplainText;
Encrypt plaintext
encryptTextplainTextmatrixSize keyMatrix;
Output ciphertext
outputCiphertextplainText;
return ;
Function to read the encryption key file
void readKeyFilechar keyFileNameint matrixSizeint keyMatrix
FILE keyFile fopenkeyFileNamer;
if keyFile NULL
printfError opening key file.
;
exit;
fscanfkeyFiledmatrixSize;
if matrixSize matrixSize
printfInvalid matrix size.
;
exit;
for int i ; i matrixSize; i
for int j ; j matrixSize; j
fscanfkeyFiled&keyMatrixij;
fclosekeyFile;
Function to read plaintext file and store only letters in lowercase
int readPlainTextFilechar plainTextFileNamechar plainText
FILE plainTextFile fopenplainTextFileNamer;
if plainTextFile NULL
printfError opening plaintext file.
;
exit;
int index ;
char ch;
while ch fgetcplainTextFileEOF && index MAXFILESIZE
if isalphach
plainTextindextolowerch;
plainTextindex;
fcloseplainTextFile;
return index; Return the number of letters read
Function to encrypt plaintext using Hill cipher
void encryptTextchar plainTextint matrixSize, int keyMatrix
Implementation of Hill cipher encryption
This part is left for you to implement
Function to output ciphertext to the console
void outputCiphertextchar ciphertext
int index ;
while ciphertextindex
printfcciphertextindex;
if index
printf
;
index;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started