Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 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;
  20. int i;
  21.  
  22. int rev = 0;
  23.  
  24. msg.open("EncryptedMessage.bin", ios::binary);
  25.  
  26. vector<unsigned char> vec((std::istreambuf_iterator<char>(msg)),std::istreambuf_iterator<char>());
  27. vector<unsigned char>::iterator it = vec.begin();
  28.  
  29. for (i = 0; i < 3; i++)
  30. {
  31. for (int a = 0; a < 3; a++)
  32. {
  33. for (int b = 0; b < 256; b++)
  34. {
  35. for (int c = 0; c < 1000; c++)
  36. {
  37. cur.operationCode = a;
  38. cur.operationParameter = b;
  39. cur.legnthToOperateOn = c;
  40.  
  41. if (int(cur.operationCode) == 0)
  42. {
  43. for (int j = 0; j < cur.legnthToOperateOn; j++)
  44. {
  45. *it ^= int(cur.operationParameter);
  46.  
  47. if (rev == 1)
  48. it--;
  49. else if (rev == 0)
  50. it++;
  51.  
  52. if (it == vec.end())
  53. {
  54. rev = 1;
  55. it--;
  56. }
  57. else if (it == vec.begin())
  58. rev = 0;
  59. }
  60. }
  61. else if (int(cur.operationCode) == 1)
  62. {
  63. for (int j = 0; j < cur.legnthToOperateOn; j++)
  64. {
  65. *it += int(cur.operationParameter);
  66.  
  67. if (rev == 1)
  68. it--;
  69. else if (rev == 0)
  70. it++;
  71.  
  72. if (it == vec.end())
  73. {
  74. rev = 1;
  75. it--;
  76. }
  77. else if (it == vec.begin())
  78. rev = 0;
  79. }
  80. }
  81. else if (int(cur.operationCode) == 2)
  82. {
  83. for (int j = 0; j < cur.legnthToOperateOn; j++)
  84. {
  85. *it -= int(cur.operationParameter);
  86.  
  87. if (rev == 1)
  88. it--;
  89. else if (rev == 0)
  90. it++;
  91.  
  92. if (it == vec.end())
  93. {
  94. rev = 1;
  95. it--;
  96. }
  97. else if (it == vec.begin())
  98. rev = 0;
  99. }
  100. }
  101. }
  102. }
  103. }
  104.  
  105.  
  106. }
  107.  
  108. for (std::vector<unsigned char>::const_iterator i = vec.begin(); i != vec.end(); ++i)
  109. std::cout << *i;
  110.  
  111. msg.close();
  112.  
  113. return 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement