Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 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.  
  25. };
  26.  
  27. class WeirdMachine
  28. {
  29. private:
  30. vector<WeirdRotor> rotors;
  31. int x;
  32.  
  33. public:
  34. WeirdMachine()
  35. {
  36.  
  37. //ifstream rotorFile("Rotors.txt");
  38.  
  39. ifstream rotorFile;
  40. rotorFile.open("Rotors.txt");
  41.  
  42. if(!rotorFile.is_open())
  43. {
  44. cout<<"dang"<<endl;
  45. }
  46.  
  47. while (rotorFile.good())
  48. {
  49. int mult, adder;
  50. rotorFile>>mult;
  51. rotorFile>>adder;
  52.  
  53. WeirdRotor r;
  54. rotors.push_back(r);
  55. }
  56. if(!rotorFile.good())
  57. {
  58. cout<<"failed not good"<<endl;
  59. break;
  60. }
  61.  
  62. }
  63.  
  64.  
  65. vector<WeirdRotor> getRotors() const
  66. {
  67. return rotors;
  68. }
  69.  
  70.  
  71. int weirdEncode(int convertedNumber)
  72. {
  73. for (WeirdRotor wr : rotors)
  74. {
  75. convertedNumber = wr.encrypt(convertedNumber);
  76. }
  77.  
  78. return convertedNumber;
  79. }
  80.  
  81.  
  82.  
  83. };
  84.  
  85.  
  86. int main()
  87. {
  88. WeirdMachine wm;
  89.  
  90. vector<WeirdRotor> testing = wm.getRotors();
  91.  
  92. cout<<testing.size()<<endl;
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. char ch;
  101. while (cin.get(ch))
  102. {
  103. int convertedNumber = static_cast<int>(ch);
  104.  
  105. if (convertedNumber == 26)
  106. {
  107. break;
  108. }
  109. cout<<wm.weirdEncode(convertedNumber)<<" ";
  110.  
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement