Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. using namespace std;
  5.  
  6.  
  7. class WeirdRotor
  8. {
  9. private:
  10. int multiplier;
  11. int adder;
  12.  
  13. public:
  14. WeirdRotor(int mult, int add) : multiplier(mult), adder(add)
  15. {
  16.  
  17. }
  18.  
  19. int encrypt(int number)
  20. {
  21. return number * multiplier + adder;
  22. }
  23.  
  24. int decrypt(int othernumber)
  25. {
  26. return othernumber - adder / multiplier;
  27. }
  28.  
  29.  
  30. };
  31.  
  32. class WeirdMachine
  33. {
  34. private:
  35. vector<WeirdRotor> rotors;
  36.  
  37. public:
  38. WeirdMachine()
  39. {
  40.  
  41. //ifstream rotorFile("Rotors.txt");
  42.  
  43. ifstream rotorFile;
  44. rotorFile.open("Rotors.txt");
  45.  
  46. if(!rotorFile.is_open())
  47. {
  48. cout<<"dang"<<endl;
  49. }
  50.  
  51. while (true)
  52. {
  53. int mult, add;
  54. rotorFile>>mult;
  55. //cout<<mult<<endl;
  56. rotorFile>>add;
  57. //cout<<add<<endl;
  58.  
  59. WeirdRotor r(mult,add);
  60. rotors.push_back(r);
  61.  
  62. if(rotorFile.eof())
  63. {
  64. break;
  65. }
  66.  
  67. if(rotorFile.fail())
  68. {
  69. cout<<"failed not good"<<endl;
  70. break;
  71. }
  72. }
  73.  
  74.  
  75. }
  76.  
  77.  
  78. vector<WeirdRotor> getRotors() const
  79. {
  80. return rotors;
  81. }
  82.  
  83.  
  84. int weirdEncode(int convertedNumber)
  85. {
  86. for (WeirdRotor wr : rotors)
  87. {
  88. convertedNumber = wr.encrypt(convertedNumber);
  89. }
  90.  
  91. return convertedNumber;
  92. }
  93.  
  94. int decode(int convertnumber)
  95. {
  96.  
  97. for (WeirdRotor rr : rotors)
  98. {
  99. for (int i = rotors.size()-1; i >= 0; i--)
  100. convertnumber = rr.decrypt(convertnumber);
  101. }
  102. return convertnumber;
  103. }
  104.  
  105.  
  106.  
  107.  
  108. };
  109.  
  110.  
  111. int main()
  112. {
  113. WeirdMachine wm;
  114.  
  115. //vector<WeirdRotor> testing = wm.getRotors();
  116.  
  117. //cout<<testing.size()<<endl;
  118.  
  119.  
  120. int ascii;
  121.  
  122.  
  123. while (cin>>ascii)
  124. {
  125.  
  126. if (ascii == 26 )
  127. {
  128. break;
  129. }
  130. cout<<wm.decode(ascii)<<" ";
  131. char convertnumber = static_cast<char>(ascii);
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement