Skip to content

Instantly share code, notes, and snippets.

@dvdbng
Created July 20, 2015 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvdbng/3683318703e1b448d87c to your computer and use it in GitHub Desktop.
Save dvdbng/3683318703e1b448d87c to your computer and use it in GitHub Desktop.
Number of possible Enigma machine combinations
# 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