From: Neil Smith Date: Mon, 23 Jun 2014 16:25:12 +0000 (+0100) Subject: Tweaked the keyword break slides X-Git-Url: https://git.njae.me.uk/?p=cipher-training.git;a=commitdiff_plain;h=646ce7a27ca04a3c9dd3c683ca1e62abafd833c9 Tweaked the keyword break slides --- diff --git a/slides/keyword-break.html b/slides/keyword-break.html index 4a2772c..49160bb 100644 --- a/slides/keyword-break.html +++ b/slides/keyword-break.html @@ -86,6 +86,28 @@ But before we get there, a couple of diversions... --- +# DRYing code + +Three cipher breaking tasks so far. + +All working on the same principle: + +``` +find a way to enumerate all the possible keys +initialise 'best so far' +for each key: + decipher message with this key + score it + if it's better than the best so far: + update best so far +``` + +Repetition of code is a bad smell. + +Separate the 'try all keys, keep the best' logic from the 'score this one key' logic. + +--- + # map() A common task is to apply a function to each item in a sequence, returning a sequence of the results.