fn guess_key_and_ring<F: FitnessFn>(msg: &str, enigma: Enigma) -> Enigma {
    let rotor = enigma.rotor_list();
    let first_key = enigma.key_settings().chars().next().unwrap();

    // Compute the key offset based on the first key setting, so that we only
    // iterate over the next 676 key settings (this implicitly fixes the slow
    // rotor's key setting at 'A', which is intentional because this setting
    // does not affect the overall decryption).
    let key_offset = first_key.index() * 676;

    let keys = &ALPHAS[key_offset..(key_offset + 676)];
    let rings = &ALPHAS[0..676];

    let (key, ring) = iproduct!(keys, rings)
        .collect::<Vec<_>>()
        .into_par_iter()
        .max_by_key(|&(key, ring)| {
            let mut enigma = Enigma::new(&rotor, key, ring, 'B', "");
            OrderedFloat(F::score(&enigma.encrypt(msg)))
        }).unwrap();

    Enigma::new(&rotor, key, ring, 'B', "")
}
/// Given a piece of ciphertext, fitness function, and an `Enigma` instance
/// with the correct rotors and first key setting, tries all key and ring
/// settings for the mid and fast rotors, and returns an `Enigma` with the
/// best rotors, key, and ring settings assigned.
///
/// This method checks 26^4 == 456,976 settings in parallel.
Given a piece of ciphertext, fitness function, and an `Enigma` instance
with the correct rotors and first key setting, tries all key and ring
settings for the mid and fast rotors, and returns an `Enigma` with the
best rotors, key, and ring settings assigned.

This method checks 26^4 == 456,976 settings in parallel.
Given a piece of ciphertext fitness function and an ` Enigma ` instance with the correct rotors and first key setting tries all key and ring settings for the mid and fast rotors and returns an ` Enigma ` with the best rotors key and ring settings assigned . This method checks 26^4 == 456 976 settings in parallel .
fn guess_key_and_ring<F: FitnessFn>(msg: &str, enigma: Enigma) -> Enigma {
    let rotor = enigma.rotor_list();
    let first_key = enigma.key_settings().chars().next().unwrap();
    // Compute the key offset based on the first key setting, so that we only
    // iterate over the next 676 key settings (this implicitly fixes the slow
    // rotor's key setting at 'A', which is intentional because this setting
    // does not affect the overall decryption).
    let key_offset = first_key.index() * 676;
    let keys = &ALPHAS[key_offset..(key_offset + 676)];
    let rings = &ALPHAS[0..676];
    let (key, ring) = iproduct!(keys, rings)
        .collect::<Vec<_>>()
        .into_par_iter()
        .max_by_key(|&(key, ring)| {
            let mut enigma = Enigma::new(&rotor, key, ring, 'B', "");
            OrderedFloat(F::score(&enigma.encrypt(msg)))
        }).unwrap();
    Enigma::new(&rotor, key, ring, 'B', "")
}
fn guess_key_and_ring < F : FitnessFn > ( msg : & str , enigma : Enigma ) -> Enigma { let rotor = enigma . rotor_list ( ) ; let first_key = enigma . key_settings ( ) . chars ( ) . next ( ) . unwrap ( ) ; // Compute the key offset based on the first key setting, so that we only // iterate over the next 676 key settings (this implicitly fixes the slow // rotor's key setting at 'A', which is intentional because this setting // does not affect the overall decryption). let key_offset = first_key . index ( ) * 676 ; let keys = & ALPHAS [ key_offset .. ( key_offset + 676 ) ] ; let rings = & ALPHAS [ 0 .. 676 ] ; let ( key , ring ) = iproduct ! ( keys rings ) . collect :: < Vec < _ > > ( ) . into_par_iter ( ) . max_by_key ( | & ( key , ring ) | { let mut enigma = Enigma :: new ( & rotor , key , ring , 'B' , " " ) ; OrderedFloat ( F :: score ( & enigma . encrypt ( msg ) ) ) } ) . unwrap ( ) ; Enigma :: new ( & rotor , key , ring , 'B' , " " ) }
Given a piece of ciphertext, fitness function, and an `Enigma` instance
with the correct rotors and first key setting, tries all key and ring
settings for the mid and fast rotors, and returns an `Enigma` with the
best rotors, key, and ring settings assigned.
Given a piece of ciphertext fitness function and an ` Enigma ` instance with the correct rotors and first key setting tries all key and ring settings for the mid and fast rotors and returns an ` Enigma ` with the best rotors key and ring settings assigned .
msg
&str
enigma
Enigma
msg
&str
enigma
Enigma