fork download
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. void encrypt_stand_message();
  8.  
  9. const char key[] = "ALCtALC sixth headed civic outlying mayflower irregular boneless prevail freebase delirious projector dreamless";
  10. const int keylen = (sizeof(key) / sizeof(key[0])) - 1;//strlen(key)
  11.  
  12. int main ()
  13. {
  14. cout << "Plese choose option?\n\n";
  15. cout << "1. Cipher text\n\n";
  16. cout << "\n";
  17.  
  18. int option = 0;
  19. cin >> option;
  20. cin.ignore();
  21.  
  22. switch (option){
  23. case 1:
  24. encrypt_stand_message();
  25. encrypt_stand_message();
  26. exit(1);
  27. }
  28. }
  29.  
  30. void encrypt_stand_message(){
  31.  
  32. int x = 0, y = 0;
  33. char cipher;
  34. char message[300];
  35.  
  36. //system("clear");
  37.  
  38. cout << "Please enter the code to encrypt?\n\n";
  39.  
  40. cin.get(message, sizeof(message));
  41. cin.ignore();
  42. cout << message << '\n';
  43.  
  44. char a = message[x];
  45. char b = key[y];
  46.  
  47. while (a != '\0'){
  48.  
  49. cipher = a ^ b;
  50.  
  51. //cout << cipher;
  52. cout << "'" << cipher << "' = " << hex << showbase << setw(2) << setfill('0') << (int)cipher << "\n";
  53.  
  54. x += 1;
  55. y += 1;
  56.  
  57. a = message[x];
  58. b = key[y % keylen];
  59. }
  60. }
Runtime error #stdin #stdout 0s 5564KB
stdin
1
alerte this is an amergency
rue rue mama mia
stdout
Plese choose option?

1. Cipher text


Please enter the code to encrypt?

alerte this is an amergency
' ' = 0x20
' ' = 0x20
'&' = 0x26
'' = 0x6
'5' = 0x35
')' = 0x29
'c' = 0x63
'T' = 0x54
'' = 0x1b
'' = 00
'' = 0xb
'T' = 0x54
'' = 0x1
'S' = 0x53
'H' = 0x48
'' = 0x4
'' = 0xf
'D' = 0x44
'' = 0x4
'	' = 0x9
'E' = 0x45
'' = 0x11
'' = 0xe
'' = 0x13
'' = 0x7
'' = 00
'Y' = 0x59
Please enter the code to encrypt?

rue rue mama mia
'3' = 0x33
'9' = 0x39
'&' = 0x26
'T' = 0x54
'3' = 0x33
'9' = 0x39
'&' = 0x26
'' = 00
'' = 0x1e
'' = 0x8
'' = 0x15
'' = 0x15
'H' = 0x48
'M' = 0x4d
'' = 0x1
'' = 0x4