Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iterator>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. struct cell
  10. {
  11. unsigned char operationCode;
  12. unsigned char operationParameter;
  13. unsigned int legnthToOperateOn;
  14. } typedef cell;
  15.  
  16. int main()
  17. {
  18. ifstream msg;
  19. cell cur, cur2, cur3;
  20. int i;
  21. int flag = 0;
  22.  
  23. int rev = 0;
  24.  
  25. msg.open("EncryptedMessage.bin", ios::binary);
  26.  
  27. vector<unsigned char> vec((std::istreambuf_iterator<char>(msg)), std::istreambuf_iterator<char>());
  28. vector<unsigned char> vecCpy = vec;
  29. vector<unsigned char>::iterator it = vec.begin();
  30.  
  31. int vecLen = vec.size();
  32.  
  33. for (int a = 0; a < 3; a++)
  34. for (int b = 0; b < 256; b++)
  35. for (int c = 0; c < vecLen; c++)
  36. {
  37. cur.operationCode = a;
  38. cur.operationParameter = b;
  39. cur.legnthToOperateOn = c;
  40. for (int j = 0; j < cur.legnthToOperateOn; j++)
  41. {
  42. switch (cur.operationCode)
  43. {
  44. case 0:
  45. *it ^= cur.operationParameter;
  46. break;
  47. case 1:
  48. *it += cur.operationParameter;
  49. break;
  50. case 2:
  51. *it -= cur.operationParameter;
  52. break;
  53. }
  54. //rev == 1 ? it-- : it++;
  55.  
  56. if (rev == 1)
  57. it--;
  58. else if (rev == 0)
  59. it++;
  60.  
  61. if (it == vec.end())
  62. {
  63. rev = 1;
  64. it--;
  65. }
  66. else if (it == vec.begin())
  67. rev = 0;
  68. }
  69. for (std::vector<unsigned char>::const_iterator i = vec.begin(); i != vec.end(); ++i)
  70. {
  71. if (*i < 32 || (*i > 32 && *i < 63) || *i == 64 || (*i > 90 && *i < 97) || *i > 122)
  72. flag = 1;
  73. else
  74. cout << *i;
  75. }
  76. cout << "\n\n";
  77. if (flag != 1)
  78. {
  79. cout << "FOUND!\n\n";
  80. for (std::vector<unsigned char>::const_iterator i = vec.begin(); i != vec.end(); ++i)
  81. std::cout << *i;
  82. }
  83.  
  84. flag = 0;
  85. vec = vecCpy;
  86. it = vec.begin();
  87. }
  88.  
  89. //for (std::vector<unsigned char>::const_iterator i = vec.begin(); i != vec.end(); ++i)
  90. //std::cout << *i;
  91.  
  92. msg.close();
  93.  
  94. return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement