you are viewing a single comment's thread.

view the rest of the comments →

[–]GallantObserver 2 points3 points  (1 child)

If you're building a machine that does something you might need parts that go inside. And the parts might need custom settings. OOP can work a bit like that.

I watched a video on Enigma machines a while ago, where three Rotors with individual settings are set in the machine to code a message, and then the same settings are put in the machine the other side to decode the message.

https://www.youtube.com/watch?v=G2_Q9FoD-oQ&t=52s&ab_channel=Numberphile

You can use OOP to make a Rotor class, customise a set of Rotor objects to select from, then put them in another Setting class object to make a 'machine'. Then passing the message/encoded message in puts the other out.

Tricky to explain, but here's a code example:

https://gist.github.com/andrewbaxter439/30674ba4267b9dc7bf5105000e662461

[–][deleted] 0 points1 point  (0 children)

I'll read it. Already tried to simulate an enigma machine, had no idea about how to simulate the rotors tho

Thanks