Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Hi. There'a code here that has a couple of /*fix me*/ lines in BOLD and I was able to do a few of them, just

Hi. There'a code here that has a couple of /*fix me*/ lines in BOLD and I was able to do a few of them, just a couple left in the lines of code below and few questions for the code. Thank You!

1 )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

2) Consider the DES algorithm instantiated with they key k="hamburgr". (This is 64 bits in ASCII. DES will automatically discard every 8th bit to arrive at a 56 bit key). In the resulting key schedule, what are C5 and D5 ? Hint: Modify the des56.c code to make it show you this value.

3) What is the AES-128 key schedule for the key k="balustraderiders"? Give the subkey used in each round. Hint: Use the code here: http://www.samiam.org/key-schedule.html

CODE BELOW

#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 < len;i++) { ctr &= 0x7; //use only right 3 bits pt[i] ^= cipher((unsigned char) (iv | ctr), key); ctr++; } }

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)); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students explore these related Databases questions