Created
July 20, 2015 16:25
-
-
Save dvdbng/3683318703e1b448d87c to your computer and use it in GitHub Desktop.
Number of possible Enigma machine combinations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Number of possible starting configurations of an enigma machine | |
letters = 26 | |
rotors_total = 5 | |
rotors_machine = 3 | |
cables = 10 # Must be < letters/2 | |
def f(n): # Factorial | |
s = 1; | |
for i in xrange(2, n+1): | |
s *= i | |
return s | |
def choose(total, howmany): # Choose howmany elements from total elements | |
return f(total)/(f(howmany)*f(total-howmany)) | |
rotors = f(rotors_total)/f(rotors_machine-1) # choose of rotors | |
rotors *= letters**rotors_machine # Starting position | |
plugboard = 1 | |
for i in xrange(0, cables): | |
plugboard *= choose(letters - i*2, 2); | |
plugboard = plugboard/f(cables) | |
print(plugboard*rotors) # 158962555217826360000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment