BRE A KING : W ON WORLD WAR T I SN CUYRB S JCNER V 5 O PLKI ODU W RCNS : Z AD SDERT STT M PYMSPQ it's been a long day, good day but long, so if you're able, please stand up for a second we're going to do a little stretch, get some blood fl owing, a few endorphins pumping diving into the pool
we're going to discuss today If you're interested in the period, I believe there have been a few movies, tv shows, even books where you can fi nd out more
morse code over radio and could be intercepted by an opponent.. in much the same way we "intercept" the local top 40 station...the messages needed to be encrypted
at this estate in Buckinghamshire was Britain's GC&CS: Government Code and Cipher School Their work kept secret until the 1970s, several thousand men and women, mostly women, mostly college aged, were tasked with cracking the German encyphering system.
be exploited, and designed a special-purpose computational engine that was made real by the engineering brilliance of Harold Keen and the British Tabulating Machine Company
‹ C odebr e ak e rs $ S incla i r ‹ M c Ka y If you're interested in hearing more about what it was like to be a part of Bletchley's operation.. I would recommend "The Secret Lives of Codebreakers" by Sinclair McKay
pairs, ⭐ one to operate the keyboard, entering the message.As a key was pressed ⭐ the corresponding letter would light up on the lampboard and be written down by the second. It worked like this...
you're unfamiliar, think of the wire as a tube that carries electricity. When the switch is down, ⭐ the signal fl ows, when that signal touches a light, it will illuminate.
C D Then the signal would be encoded. Press the "A" key ⭐ and "B" lights up. Knowing what letters connected, you would be able to decode it as well. That's the job of the enigma's encryption mechanism, it physically swaps the electrical connection between the key and the light.
special symmetric rotor called ⭐ a re fl ector. here if 1 becomes 10, 10 becomes 1. ⭐ after passing through the re fl ector, the signal would be carried back on a di ff erent path of connections.
and decrypted, because the path of the signal is symmetrical, typing the cipher character will return the original ⭐ but no matter how many times a letter is changed, it's weak if A always becomes E
the same cypher, a chart would be sent out from High command, prescribing which settings should be used on a given day. Essential coordination, because only by sharing the same starting settings would agents be able to communicate. The chart included
Dev e l o p me 1 . Requi r e me n ts wi l l ch an . 2 . We wi l l n e ve r k n ow l es t H we do r ig h t now . Let's go big right from the start with two Truths of software development ⭐ requirements will change. And this is good. If nothing needs to change, there probably aren't any users, and we'll need to fi nd another job ⭐ we will never know less than we do right now because we don't know HOW things will change
Dev e l o p me 1 . Requi r e me n ts wi l l ch an . 2 . We wi l l n e ve r k n ow l es t H we do r ig h t now . and it's frustrating when we can't make changes, right? When a new feature request comes along and we can't deliver it to users because it would be too hard to implement?
Dev e l o p me 1 . Requi r e me n ts wi l l ch an . 2 . We wi l l n e ve r k n ow l es t H we do r ig h t now . That's an awful feeling. We don't want to be there. but if we don't know anything.. and it's all going to change.. how CAN we build anything?
i i A c lass s h ou l d hav eƒ o n l y one r es p on sib i lity , 0 o n e reas o n t o c han g e Single Responsibility Principle: we'll gather together the things that change for the same reasons and separate those that change for di ff erent reasons
t h e inte n t o f a n e n o t the i m pl e me nta t ion. Abstraction: we'll manage the complexity of implementation by substituting a more-easy-to-reason-about representation
vent e x t e r nal c o de f r b i n v o l v e d w i t h t h e i w o r kings o f a n obj e ct. Encapsulation: Object's internal data should change on that object's own terms
H i g h-lev e l m o du les shou ld o i m p ort a n y th i ng fr o m lo w- v m o d ules. B ot h s hou l d de pe i n t erfac e s . Dependency Inversion: conventional architecture would have utility modules (low-level) consumed by higher-level ones, but we'll invert this thinking and increase reuse from top to bottom through interfaces
n c S o f tware e nt i ti es s houl d f o r exte n s io n , but clos ed ¡ f o r modi f i ca t io n. Open/Closed Principle: an object should allow its behavior to be extended without modifying it's own code.
methods, tests we write will be de fi ned inside a class that inherits from Minitest::Test we can get things moving by thinking at a high level. What does our Enigma need to do?
0 errors, 0 skips > ruby enigma_test.rb We invoke the test fi le from the command line. By requiring 'minitest/autorun' like we have, Minitest will fi nd all the runnable subclasses and tell them to do their thing. ⭐ which right now is to fail
2 failures, 0 errors, 0 skips > we can make sure it's not "A", and that cyphering "B" isn't the same result. Is this test going to pass? ⭐ No! of course not
Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # On branch RubyConf # Changes to be committed: Adds initial Enigma class w/ cypher method Adds initial Enigma class w/ cypher method
Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # On branch RubyConf # Changes to be committed: Adds initial Enigma class w/ cypher method Made use of Test Driven Development flow, and set up initial Enigma file and functionality. Made use of Test Driven Development fl ow, and set up initial Enigma fi le and functionality.
Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # On branch RubyConf # Changes to be committed: Adds initial Enigma class w/ cypher method Made use of Test Driven Development flow, and set up initial Enigma file and functionality. The person in the front row over here really liked it. The person in the front row over here really liked it.
Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # On branch RubyConf # Changes to be committed: Adds initial Enigma class w/ cypher method Made use of Test Driven Development flow, and set up initial Enigma file and functionality. The person in the front row over here really liked it. He was nodding _a lot_. He was nodding _a lot_
0 failures, 0 errors, 0 skips > replace all the `ALPHABET.index` calls with our new method, and radio for backup ⭐ Situation green, 10-4 good buddy, over and out
Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # on branch RubyConf Extracts alpha_index and translate to private methods Did it work? Commit! ⭐ Extracts alpha_index and translate to private methods.
Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # on branch RubyConf Extracts alpha_index and translate to private methods We gathered the lines that would change for the same reason. We gathered the lines that would change for the same reason.
Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # on branch RubyConf Extracts alpha_index and translate to private methods We gathered the lines that would change for the same reason. Guided by The Single Responsibility Principle to create a single source of truth for those behaviors. Guided by The Single Responsibility Principle to create a single source of truth for those behaviors.
> # Running... ... 3 runs, 6 assertions, 0 failures, 0 errors, 0 skips we're at a point where all the pieces should fi t together again, but do our tests agree? ⭐ oh! we also have more than one test fi le now, so we'll use a little ruby command line magic to run every fi le that ends in `_test.rb` ⭐ magni fi cent
E Iƒ Fƒ Gƒ Cƒ Bƒ Eƒ Dƒ Hƒ A Aƒ Bƒ Cƒ Dƒ Eƒ Fƒ Gƒ Hƒ I Fƒ Gƒ Hƒ I Hƒ Fƒ Eƒ Dƒ Gƒ Aƒ Iƒ Bƒ C Cƒ Dƒ Iƒ Hƒ Aƒ Dƒ Eƒ Bƒ F Dƒ Eƒ Aƒ Cƒ Fƒ Bƒ Gƒ Iƒ H 0 5 4 8 A I Because we're converting alpha to int and back between each rotor, we're not correctly following the connections through our device. ⭐ How do we correct? ⭐ integers the whole way through, convert only up front and at the end.
"commit!" 👆 did it work? 👉 (commit!) alright. some of you were paying attention. some of you weren't. s'okay... I'll get over it.... eventually. (( SKIP SUCCESS KID IF NO RESPONSE AT ALL ))
Lines starting Extracts alpha/int translation to classes of their own (again) 👆 did it work? 👉 (commit!) ⭐ alright! I'm not the only person that thinks this looks like a young Patton Oswalt, am I? This commit.. extracts alpha/int translation to classes of their own
Lines starting Extracts alpha/int translation to classes of their own (again) 👆 did it work? 👉 (commit!) ⭐ alright! This commit.. extracts alpha/int translation to classes of their own
Lines starting Extracts alpha/int translation to classes of their own Before this, Enigma methods contained the code that implemented the behavior, preventing flexibility and reuse. Before this, Enigma methods contained the code that implemented the behavior, preventing fl exibility and reuse.
Lines starting Extracts alpha/int translation to classes of their own Before this, Enigma methods contained the code that implemented the behavior, preventing flexibility and reuse. We extracted self-contained functionality, replacing the specific code with a message sent to new collaborators. We extracted self-contained functionality, replacing the speci fi c code with a message sent to new collaborators.
Lines starting Extracts alpha/int translation to classes of their own Before this, Enigma methods contained the code that implemented the behavior, preventing flexibility and reuse. We extracted self-contained functionality, replacing the specific code with a message sent to new collaborators. This abstraction makes Enigma lighter, easier to understand, and opens it to new functionality. The Smaller classes offer utility and reuse to other parts of a larger system. This abstraction makes Enigma lighter, easier to understand, and opens it to new functionality. The Smaller classes o ff er utility and reuse to other parts of a larger system.
# Running... .F... 5 runs, 9 assertions, 1 failures, 0 errors, 0 skips > and a failure is the precise result we expected here, we have written no new code.
# Running... .....E 6 runs, 11 assertions, 0 failures, 1 errors, 0 skips > and we expected that, this is predetermined after all... and we have the wrong number of arguments to `.new`
Lines starting Extracts Rotor class The things that don't align to Enigma's purpose are in their own classes, and we're left with a clear picture of what the Enigma class does The things that don't align to Enigma's purpose are in their own classes, and we're left with a clear picture of what the Enigma class does
Enigma's purpose are in their own classes, and we're left with a clear picture of what the Enigma class does Orchestrates and conducts the communication between these different pieces so they can stay separate from each other. # Please enter the commit message for your changes. Lines starting Orchestrates and conducts the communication between these di ff erent pieces so they can stay separate from each other.
Lines starting Extracts Rotor class The things that don't align to Enigma's purpose are in their own classes, and we're left with a clear picture of what the Enigma class does Orchestrates and conducts the communication between these different pieces so they can stay separate from each other. A rotor doesn't have to know what comes before or after it, and Enigma doesn't know how the work gets done. That's Dependency Inversion at work. A rotor doesn't have to know what comes before or after it, and Enigma doesn't know how the work gets done. That's Dependency Inversion at work.
tests be straightforward. Coming along and reading this test later when we've forgotten what we wrote shouldn't take a lot of energy. minitest, you have anything to say?
# Running... .E....FF... 11 runs, 20 assertions, 2 failures, 1 errors, 0 skips > now position is part of how we calculate what index to return ⭐ and it passes the fi rst test
fi rst index in an array to the back, with an argument for how many times to rotate. also notice, does anybody else get to see this method? nope. private. ⭐ 🌈 encapsulation🌈
# Running... ........FF... 13 runs, 22 assertions, 2 failures, 0 errors, 0 skips > the rotor tests pass, and we have what we need to make the enigma tests function so back we go
# Running... ............. 13 runs, 22 assertions, 0 failures, 0 errors, 0 skips > how'd we hold up? ⭐ Ver! di! gris! oh Verdigris? that's the green patina on copper..like the statue of liberty. this is getting away from me.
Lines starting # with '#' will be ignored, and an empty message aborts the commit. Implements rotor stepping behavior this commit implements rotor stepping behavior
Lines starting # with '#' will be ignored, and an empty message aborts the commit. Implements rotor stepping behavior With new behavior, Enigma is no longer a weak substitution cypher With new behavior, Enigma is no longer a weak substitution cypher
Lines starting # with '#' will be ignored, and an empty message aborts the commit. Implements rotor stepping behavior With new behavior, Enigma is no longer a weak substitution cypher We safeguarded the rotor's internal data, only allowing it to change via a method without exposing how the behavior is accomplished. We safeguarded the rotor's internal data, only allowing it to change via a method without exposing how the behavior is accomplished.
Lines starting # with '#' will be ignored, and an empty message aborts the commit. Implements rotor stepping behavior With new behavior, Enigma is no longer a weak substitution cypher By encapsulating this information, we're also protecting Rotor's collaborators from the responsibility of knowing this is what Rotors do. We safeguarded the rotor's internal data, only allowing it to change via a method without exposing how the behavior is accomplished. By encapsulating this information, we're also protecting Rotor's collaborators from the responsibility of knowing this is what Rotors do.
There's the mechanism that advances the rotors, the re fl ector, and the Spindle that the rotors sit on. We need a new small simple object to send messages to.
of OO design, it doesn't even matter. Just.. pass in a di ff erent transformer. Want to use elliptic curve cryptography? go right ahead. Want to use MD5? 1993 called and they want their algorithm back but you can! I'm excited! are you excited? [[ front row's excited! ]]
# Running... ............. 14 runs, 24 assertions, 0 failures, 0 errors, 0 skips > green green green.. green like, i dunno all the little dots in the terminal
Lines starting # with '#' will be ignored, and an empty message aborts the commit. # Abstracts encyphering away from Enigma's responsibility This commit abstracts encyphering away from Enigma's responsibility.
Lines starting # with '#' will be ignored, and an empty message aborts the commit. # Abstracts encyphering away from Enigma's responsibility Enigma is Open for Extension and Closed for Modification enabling painless re-use in ways we don't have to try and predict. Enigma is Open for Extension and Closed for Modi fi cation, enabling painless re-use in ways we don't have to try and predict.
Lines starting # with '#' will be ignored, and an empty message aborts the commit. # Abstracts encyphering away from Enigma's responsibility Enigma is Open for Extension and Closed for Modification enabling painless re-use in ways we don't have to try and predict. Lead by OO Design principles we built a replica Enigma that is easy and fun to work with... Lead by OO Design principles we built a replica Enigma that is easy and fun to work with.
Lines starting # with '#' will be ignored, and an empty message aborts the commit. # Abstracts encyphering away from Enigma's responsibility Enigma is Open for Extension and Closed for Modification enabling painless re-use in ways we don't have to try and predict. Lead by OO Design principles we built a replica Enigma that is easy and fun to work with... ...using tech and ideas that stand of the shoulders of giants like using tech and ideas that stand on the shoulders of giants like
Lines starting # with '#' will be ignored, and an empty message aborts the commit. # Abstracts encyphering away from Enigma's responsibility Enigma is Open for Extension and Closed for Modification enabling painless re-use in ways we don't have to try and predict. Lead by OO Design principles we built a replica Enigma that is easy and fun to work with... ...using tech and ideas that stand of the shoulders of giants like Alan Turing Alan Turing
Lines starting # with '#' will be ignored, and an empty message aborts the commit. # Abstracts encyphering away from Enigma's responsibility Enigma is Open for Extension and Closed for Modification enabling painless re-use in ways we don't have to try and predict. Lead by OO Design principles we built a replica Enigma that is easy and fun to work with... ...using tech and ideas that stand of the shoulders of giants like Alan Turing, John von Neumann John von Neumann
Lines starting # with '#' will be ignored, and an empty message aborts the commit. # Abstracts encyphering away from Enigma's responsibility Enigma is Open for Extension and Closed for Modification enabling painless re-use in ways we don't have to try and predict. Lead by OO Design principles we built a replica Enigma that is easy and fun to work with... ...using tech and ideas that stand of the shoulders of giants like Alan Turing, John von Neumann, Grace Hopper Grace Hopper
Lines starting # with '#' will be ignored, and an empty message aborts the commit. # Abstracts encyphering away from Enigma's responsibility Enigma is Open for Extension and Closed for Modification enabling painless re-use in ways we don't have to try and predict. Lead by OO Design principles we built a replica Enigma that is easy and fun to work with... ...using tech and ideas that stand of the shoulders of giants like Alan Turing, John von Neumann, Grace Hopper and Yukihiro Matsumoto. and Yukihiro Matsumoto ⭐ what a ride!
ty A bstr acti o n E ncap sula t ion D epen denc y Inve r s i o n Dependency Inversion: Higher level objects operate without being involved in the speci fi cs of those they send messages to.
ty A bstr acti o n E ncap sula t ion O pen/ Clos e d D epen denc y Inve r s i o n Open for extension and closed for modi fi cation...because we don't even need to!
¡ o n R a il s d ocu ment a t i o n H . . .b u t l i k e f or f u n s i es F o un d w h e r eve r yo u g e t y ou r p odc asts , b u t h ey t r y O verc a s t - > c o de im a g e s m ade w i t h c o m e s a y h i a t t h e t h o u g h t b o t b o o t h If you want to chat about more features to implement with Enigma, we didn't even get to the re fl ector or the plugboard, or a lampboard that returns html instead of a string, or a keyboard that's an api endpoint, or maybe you too have feelings about how Turing was murdered by his own government? or want to chat about Bletchley Park.. or like.. Object Orientation.. I'm going to be hanging around the thoughtbot booth a lot tomorrow, come say hi.