0

error: "invalid operands of types ‘long double’ and ‘long double’ to binary ‘operator^’"

 long double plain_text, encryption_key, encrypt, decrypt;

cout << "Enter plain text (corresponding decimal value) : " << endl;
cin >> plain_text;
cout << "Enter key (corresponding decimal value) : " << endl;
cin >> encryption_key;

bitset<128> w(plain_text);
cout << " Your plain text bit stream is: " << setw(5) << w << endl;

bitset<128> x(encryption_key);
cout << " Your key text bit stream is: " << setw(5) << x << endl;

encrypt = plain_text ^ encryption_key;
bitset<128> y(encrypt);
cout << "Your cipher text bitstream is: " << setw(5) << y;

decrypt = encrypt ^ encryption_key;
bitset<128> z(decrypt);
cout << "Your plain text bitstream is: " << setw(5) << z;

return 0;
  • What are you hoping `^` will do, when located between two `double`s? The "why" is, as the error states, because it has no valid meaning. – Drew Dormann Nov 10 '21 at 16:25
  • 2
    `plain_text ^ encryption_key` you can't XOR (`^`) floating point numbers. – Richard Critten Nov 10 '21 at 16:25
  • I see. Didn't knew this. Thanks – HAPPY LAMMA Nov 10 '21 at 16:27
  • 1
    @HAPPYLAMMA Because floating point is hard, I would strongly suggest never using it in any form of encryption see [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – Richard Critten Nov 10 '21 at 16:30
  • but i am asked to take 128 bit numerical input and perform encryption and decryption using XOR and 1 data type i found is 16byte is long double. – HAPPY LAMMA Nov 10 '21 at 16:34
  • no idea what i should do now – HAPPY LAMMA Nov 10 '21 at 16:34
  • @HAPPYLAMMA -- *but i am asked to take 128 bit numerical input* -- Use a big integer library that is made to handle this, not floating point. Plenty of options are available. Also, who gave you this assignment? I'm sure they are well aware that few, if any C++ compilers have 128-bit integers (maybe there is one out there, I don't know), and that you either have to come up with the code, or use a library to simulate 128-bit integers. – PaulMcKenzie Nov 10 '21 at 16:36
  • plz suggest me some – HAPPY LAMMA Nov 10 '21 at 16:39
  • [Big integer](https://stackoverflow.com/questions/12988099/big-numbers-library-in-c) – PaulMcKenzie Nov 10 '21 at 16:41
  • Why not process the input as character data (`std::string` or `char[]`) why convert to integer types? – Richard Critten Nov 10 '21 at 16:44
  • Abseil [int128](https://github.com/abseil/abseil-cpp/blob/master/absl/numeric/int128.h). – Eljay Nov 10 '21 at 16:59

0 Answers0