Question

C++ XOR two strings. I am trying to XOR two strings 00112233445566778899AABBCCDDEEFFAABB060606060606 and 4ca00fd6dbf1fb284ca00fd6dbf1fb284ca00fd6dbf1fb28 my program...

C++ XOR two strings.

I am trying to XOR two strings

00112233445566778899AABBCCDDEEFFAABB060606060606

and

4ca00fd6dbf1fb284ca00fd6dbf1fb284ca00fd6dbf1fb28

my program is giving me: SPTWPVSPT[X   q'&t'!"u#'t~u"#rPTTTVVT as a result

However, when i go to http://xor.pw/? and input the two hexadecimal strings in I get the result: 4cb12de59fa49d5fc439a56d172c15d7e61b09d0ddf7fd2e

what am I doing wrong in my program below?

// plaintext value here
string pthex = "00112233445566778899AABBCCDDEEFFAABB";
// IV value here
string sHex = "4ca00fd6dbf1fb28";
string PaddedPlainText = pthex + "060606060606"; //added the pad
//cout<<PaddedPlainText<<endl;
// the above hex valus should be passed in .

int PPTextLength = PaddedPlainText.length(); // length of plaintext
int BlockCounter = (PPTextLength / 16);      // number of blocks to process

cout<<"Pa: "<<PaddedPlainText<<endl;
cout<<"IV: "<<sHex<<endl;
cout<<"Blocks: "<<BlockCounter<<endl;

string XORval;
string vXOR;

for (int i=1; i<=BlockCounter; i++)
{
    cout<<"I is: "<< i<<endl;
    if (i == 1)
        for (int j=0;j<16;j++)
        {
            //cout<<sHex.at(j)<<" "<<PaddedPlainText.at(j)<<endl;
            XORval = sHex.at(j)^PaddedPlainText.at(j);
            vXOR.append(XORval);
            //cout<<XORval<<endl;
        }
    else if (i > 1)
        for (int j =((i*16)-16); j < (((i)*16));j++)
        {
           // cout<<"the value of i: "<<i<<" the valiue of j: "<<j<<endl;
           // cout<<sHex.at((j-((i*16)-16)))<<" "<<PaddedPlainText.at(j)<<endl;
            XORval = sHex.at((j-((i*16)-16)))^PaddedPlainText.at(j);
            vXOR.append(XORval);
           // cout<<vXOR<<endl;
        }
        cout<<vXOR<<endl;
}
return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<sstream>

#include<iostream>

using namespace std;

int ConvertHexToInteger(char ch){

if(ch>='0' && ch<='9')

return(ch-48);

else if(ch>='A' && ch<='Z')

return(ch-55);

else

return(ch-87);

}

string XORtwoStrings(string A, string B){

std::stringstream xoredString;

for(int i=0;i<B.length();i++){

xoredString << hex << (ConvertHexToInteger(A[i])^ConvertHexToInteger(B[i]));

}

return xoredString.str();

}

int main(){

string a = "00112233445566778899AABBCCDDEEFFAABB060606060606";

string b = "4ca00fd6dbf1fb284ca00fd6dbf1fb284ca00fd6dbf1fb28";

cout<<"XOR of two Hex String is: " << endl;

cout<<XORtwoStrings(a,b)<<endl;

}
===============================================================================
See The Output
c4b301bb9697:Chegg kundrars vi XORstrings.cpp c4b301bb9697:Chegg kundrar$ ./a.out XOR of two Hex String is: 4cb12de59fa49d5fc

Thanks, let me know if there is any concern.

Add a comment
Know the answer?
Add Answer to:
C++ XOR two strings. I am trying to XOR two strings 00112233445566778899AABBCCDDEEFFAABB060606060606 and 4ca00fd6dbf1fb284ca00fd6dbf1fb284ca00fd6dbf1fb28 my program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am trying to do this assignment: Write a program that reads a list of concepts/strings...

    I am trying to do this assignment: Write a program that reads a list of concepts/strings from the LIST.txt text file (one concept per line), stores them into an array of strings, and then prints the following: 1.Prints a heading “LIST1:” and then prints all the concepts from the array, one concept per line 2.Prints a heading “LIST2:” and then prints all the concepts from the array that do not contain spaces, one concept per line 3.Prints a heading “LIST3:”...

  • The following program is in c++ ; I am trying to read in games from a...

    The following program is in c++ ; I am trying to read in games from a file and when doing so I am only reading in parts of the file. It is giving me a segmentation fault error I am going to post my code below if anyone is able to help me debug the program I would greatly appreciate it. The program is too large to be submitted as a single question on here :( --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- void Business::addGamesFromFile() {...

  • Hey, so i am trying to have my program read a text file using a structure...

    Hey, so i am trying to have my program read a text file using a structure but i also want to be able to modify the results(I kinda have this part but it could be better). I cant seem to get it to read the file(all the values come up as 0 and i'm not sure why because in my other program where it wrote to the txt file the values are on the txt file) i copied and pasted...

  • Hello, The C++ question is: ------------------------------------------------------------------------------- Write a program that takes as input 2 strings from...

    Hello, The C++ question is: ------------------------------------------------------------------------------- Write a program that takes as input 2 strings from the user. Then it determines if one string is a permutation of the other string. If the program answers "yes" to the previous question, meaning the two strings are permutations of each other, determine if each string has all unique characters. --------------------------------------------------------------------------------- I have completed the first part but I am unsure on how to also determine if each string is all unique characters...

  • C++ problem. hi heys, i am trying to remove beginning and the end whitespace in one...

    C++ problem. hi heys, i am trying to remove beginning and the end whitespace in one file, and output the result to another file. But i am confused about how to remove whitespace. i need to make a function to do it. It should use string, anyone can help me ? here is my code. #include <iostream> #include <iomanip> #include <cstdlib> #include <fstream> using namespace std; void IsFileName(string filename); int main(int argc, char const *argv[]) { string inputfileName = argv[1];...

  • Why am I getting the same results with my rand() every time I run my C++...

    Why am I getting the same results with my rand() every time I run my C++ program? I am trying to do this problem: each receive $200 per week plus 9 percent of their gross sales for that week. For example, a salesperson who grosses $5000 in sales in a week receives $200 plus 9 percent of $ 5000, or a total of $650. Write a program(using an array of counters) that determines how many of the salespeople earned salaries...

  • Hello everyone! I am working on my assignment for C++ and I'm having a bit of...

    Hello everyone! I am working on my assignment for C++ and I'm having a bit of trouble on the value producing functions, I am creating a program wherein I have to input a value and I need to create a function called square value where in it will square the value I have input. I cannot seem to figure out this part. Here is the code that I have so far, and thank you for any help. I greatly appreciate...

  • I wrote a card shuffle program and I am trying to see how I can add...

    I wrote a card shuffle program and I am trying to see how I can add a sorting function to the program to sort the players hands before printing them. How would I do this? #include <iostream> #include <iomanip> #include <vector> #include <algorithm> using namespace std; void printHand(int []); void deal(vector<int> &, int[], int[], int[], int[]); void unwrapDeck(vector<int> &deck) { for(int i=0; i<=51; i++) deck.push_back(i); } void shuffleDeck(vector<int> &deck) { //Status of cards before shuffling cout << "Before shuffling: "...

  • I'm kind of new to programming, and I am having trouble figuring out why my program...

    I'm kind of new to programming, and I am having trouble figuring out why my program isn't running. Below is the code that I wrote for practice. I will comment where it says the error is. So the error that I'm getting is "error: no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' ". I'm not sure why I'm getting this because I added the library <iostream> at the top. Thank you. Code: #include <iostream> using namespace std; class...

  • c++, I am having trouble getting my program to compile, any help would be appreciated. #include...

    c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT