Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- using namespace std;
- class WeirdRotor
- {
- private:
- int multiplier;
- int adder;
- public:
- WeirdRotor(int mult, int add) : multiplier(mult), adder(add)
- {
- }
- int encrypt(int number)
- {
- return number * multiplier + adder;
- }
- int decrypt(int othernumber)
- {
- return othernumber - adder / multiplier;
- }
- };
- class WeirdMachine
- {
- private:
- vector<WeirdRotor> rotors;
- public:
- WeirdMachine()
- {
- //ifstream rotorFile("Rotors.txt");
- ifstream rotorFile;
- rotorFile.open("Rotors.txt");
- if(!rotorFile.is_open())
- {
- cout<<"dang"<<endl;
- }
- while (true)
- {
- int mult, add;
- rotorFile>>mult;
- //cout<<mult<<endl;
- rotorFile>>add;
- //cout<<add<<endl;
- WeirdRotor r(mult,add);
- rotors.push_back(r);
- if(rotorFile.eof())
- {
- break;
- }
- if(rotorFile.fail())
- {
- cout<<"failed not good"<<endl;
- break;
- }
- }
- }
- vector<WeirdRotor> getRotors() const
- {
- return rotors;
- }
- int weirdEncode(int convertedNumber)
- {
- for (WeirdRotor wr : rotors)
- {
- convertedNumber = wr.encrypt(convertedNumber);
- }
- return convertedNumber;
- }
- int decode(int convertnumber)
- {
- for (WeirdRotor rr : rotors)
- {
- for (int i = rotors.size()-1; i >= 0; i--)
- convertnumber = rr.decrypt(convertnumber);
- }
- return convertnumber;
- }
- };
- int main()
- {
- WeirdMachine wm;
- //vector<WeirdRotor> testing = wm.getRotors();
- //cout<<testing.size()<<endl;
- int ascii;
- while (cin>>ascii)
- {
- if (ascii == 26 )
- {
- break;
- }
- cout<<wm.decode(ascii)<<" ";
- char convertnumber = static_cast<char>(ascii);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement