fork(1) download
  1. #include <string>
  2. #include <iostream>
  3.  
  4. void cbc_encrypt(char iv, char key, const char* text, std::size_t size, char* buf)
  5. {
  6. while (size--)
  7. {
  8. *buf = iv ^ (key ^ *text++);
  9. iv = *buf++;
  10. }
  11. }
  12.  
  13. void cbc_decrypt(char iv, char key, const char* text, std::size_t size, char* buf)
  14. {
  15. while (size--)
  16. {
  17. *buf++ = iv ^ (key ^ *text);
  18. iv = *text++;
  19. }
  20. }
  21.  
  22. int main()
  23. {
  24. std::string msg;
  25.  
  26. while (std::getline(std::cin, msg))
  27. {
  28. std::string enc(msg.size(), char());
  29. cbc_encrypt('a', 'k', msg.data(), msg.size(), &enc[0]);
  30. cbc_decrypt('a', 'k', enc.data(), enc.size(), &msg[0]);
  31.  
  32. std::cout << "Encrypted: " << enc << '\n';
  33. std::cout << "Decrypted: " << msg << '\n';
  34. }
  35. }
Success #stdin #stdout 0s 3436KB
stdin
bbbbbbbb
stdout
Encrypted: hahahaha
Decrypted: bbbbbbbb