fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. void charout(wstring const& str)
  7. {
  8. for (unsigned i = 0 ; i < str.length(); ++i)
  9. cout << static_cast<int>(str[i]) << ' ';
  10. cout << '\n';
  11. }
  12.  
  13. int main()
  14. {
  15. wstring toEncrypt = L"Test\u04EE";
  16. wchar_t keyToEncrypt = 'd';
  17.  
  18. cout << "Before: ";
  19. charout(toEncrypt);
  20.  
  21. for (int temp = 0; temp < toEncrypt.size(); temp++)
  22. toEncrypt[temp] ^= keyToEncrypt;
  23. cout << "The encrypted data = ";
  24. charout(toEncrypt);
  25.  
  26. for (int temp = 0; temp < toEncrypt.size(); temp++)
  27. toEncrypt[temp] ^= keyToEncrypt;
  28. cout << "The unencrypted data = ";
  29. charout(toEncrypt);
  30. }
  31.  
Success #stdin #stdout 0.02s 2856KB
stdin
Standard input is empty
stdout
Before: 84 101 115 116 1262 
The encrypted data = 48 1 23 16 1162 
The unencrypted data = 84 101 115 116 1262