Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

image text in transcribed

#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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions