Question: #include #include #include #include hex.h #include /*The block cipher*/ char cipher(unsigned char block, char key) { //this is an affine cipher where a is fixed

 #include #include #include #include "hex.h" #include /*The block cipher*/ char cipher(unsigned

#include #include #include #include "hex.h" #include

/*The block cipher*/ char cipher(unsigned char block, char key) { //this is an affine cipher where "a" is fixed at 11 and b=key return (key+11*block)%256; }

/*The inverse of the block cipher*/ char inv_cipher(unsigned char block, char key) { // 163 is the inverse of 11 mod 256 return (163*(block-key+256))%256; }

void ofb(char* pt, char key, char iv, int len) { /*fix me*/ }

void ecb(char* pt, char key, char iv, int len) { /*fix me*/ }

void ecb_dec(char* ct, char key, char iv, int len) { /*fix me*/ }

void cfb(char* pt, char key, char iv, int len) { /*fix me*/ }

void cfb_dec(char* ct, char key, char iv, int len) { /*fix me*/ }

void cbc(char* pt, char key, char iv, int len) { /*fix me*/ }

void cbc_dec(char* ct, char key, char iv, int len) { /*fix me*/ }

void ctr(char* pt, char key, char iv, int len) { iv &= 0xF8; //use only left 5 bits int i =0, ctr=0; for(i=0; i

void print_ct(char* ct,int len) { printf("ciphertext: 0x%s ",bin2hex(ct,len)); }

/*Desired output:

plaintext: mother ciphertext: 0x2D2422090905 plaintext: soldier ciphertext: 0xF9CDAC548B5FEE plaintext: risk ciphertext: 0x24FD940F plaintext: endless ciphertext: 0xEDA9D7110425BA plaintext: hair ciphertext: 0x3EDB6F38

*/

int main() { char key = 8; char iv = 0xaa; int len; int a = 1; char ct[1000] = {0}; char pt[12][100] = {"wife", "mother", "soldier", "risk", "endless", "hair", "vote", "outside", "plate", "estate", "slow", "baby"}; char ct_ark[12][100] = {{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}};

len = strlen(pt[a]); strncpy(ct,pt[a],len); printf("plaintext: %s ",pt[a]); ctr(ct,key,iv,len); print_ct(ct,len); strncpy(ct_ark[a],ct,len); ctr(ct,key,iv,len); assert((strncmp(ct,pt[a],len)==0));

a++; len = strlen(pt[a]); strncpy(ct,pt[a],len); printf("plaintext: %s ",pt[a]); ecb(ct,key,iv,len); print_ct(ct,len); strncpy(ct_ark[a],ct,len); ecb_dec(ct,key,iv,len); assert((strncmp(ct,pt[a],len)==0));

a++; len = strlen(pt[a]); strncpy(ct,pt[a],len); printf("plaintext: %s ",pt[a]); cfb(ct,key,iv,len); print_ct(ct,len); strncpy(ct_ark[a],ct,len); cfb_dec(ct,key,iv,len); assert((strncmp(ct,pt[a],len)==0));

a++; len = strlen(pt[a]); strncpy(ct,pt[a],len); printf("plaintext: %s ",pt[a]); cbc(ct,key,iv,len); print_ct(ct,len); strncpy(ct_ark[a],ct,len); cbc_dec(ct,key,iv,len); assert((strncmp(ct,pt[a],len)==0));

a++; len = strlen(pt[a]); strncpy(ct,pt[a],len); printf("plaintext: %s ",pt[a]); ofb(ct,key,iv,len); print_ct(ct,len); strncpy(ct_ark[a],ct,len); ofb(ct,key,iv,len); assert((strncmp(ct,pt[a],len)==0)); }

Fix the functions in the file modes.c so that the output is the desired output: plaintext: mother ciphertext: 0x2D2422090905 plaintext: soldier ciphertext: 0xF9CDAC548B5FEE plaintext: risk ciphertext: 0x24FD940F plaintext: endless ciphertext: 0xEDA9D7110425BA plaintext: hair ciphertext: 0x3EDB6F38 Fix the functions in the file modes.c so that the output is the desired output: plaintext: mother ciphertext: 0x2D2422090905 plaintext: soldier ciphertext: 0xF9CDAC548B5FEE plaintext: risk ciphertext: 0x24FD940F plaintext: endless ciphertext: 0xEDA9D7110425BA plaintext: hair ciphertext: 0x3EDB6F38

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!