Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How to apply padding C++ Given string: WVOGJTXQHUHXICWYYMGHTRKQHQPWKYVGLPYSPWGOI

ID: 3765600 • Letter: H

Question

How to apply padding C++

Given string: WVOGJTXQHUHXICWYYMGHTRKQHQPWKYVGLPYSPWGOINTOFOPMO

How to output into 4 by 4 format

c. Padding Steps d - f are performed on blocks of size 4 x 4 characters formed from the output of step b (i.e., substitution). They are parts of AES and as in any block cipher, the input has to be padded. In this particular case, pad the output from the previous step with A's so that the length of the message is divisible by 16. o Example Input: WVOG JTXQ HUHX ICWY Output: WVOG JTXQ HUHX ICWY YMGH TRKO HQPW KYVG YMGH TRKO HQPW KYVG LPYS PWGO INTO FOPM LPYS PWGO INTO FOPM 0 OAAA

Explanation / Answer

#include<string>

#include<iostream>

using namespace std;

int main()

{
   string str = "WVOGJTXQHUHXICWYYMGHTRKQHQPWKYVGLPYSPWGOINTOFOPMO";
   int length = str.length();
   for(int i = 0; i < length; i++) {
       cout << str[i];
       if((i+1) %4 == 0)
           cout <<endl;
       if((i+1) %16 == 0)
                   cout <<endl;

   }

   cout << " ####################Padded array######################" <<endl;
   int rem = length % 16;
   int paddedlen = 16 - rem;
   string output = str;
   for(int i = 0; i < paddedlen; i++) {
       output += "A";
   }

   for(int i = 0; i < output.length(); i++) {
           cout << output[i];
           if((i+1) %4 == 0)
               cout <<endl;
           if((i+1) %16 == 0)
                       cout <<endl;

       }

}

---------------output-----------------------

WVOG
JTXQ
HUHX
ICWY

YMGH
TRKQ
HQPW
KYVG

LPYS
PWGO
INTO
FOPM

O
####################Padded array######################
WVOG
JTXQ
HUHX
ICWY

YMGH
TRKQ
HQPW
KYVG

LPYS
PWGO
INTO
FOPM

OAAA
AAAA
AAAA
AAAA

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote