iKevinY / ultra

Cryptanalysis of the Enigma machine in Rust.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Try optimizing fitness functions

iKevinY opened this issue · comments

This might be faster as an explicit loop where the outgoing character is modulo'd off the accumulated index, the index is multiplied by 26, then the incoming character is added in.

ultra/src/fitness.rs

Lines 66 to 69 in 5ac5ef0

char_indices.windows(n)
.map(|w| w.iter().fold(0, |acc, x| 26 * acc + x))
.map(|i| ngrams[i])
.sum()