Zacaj's Forums

Programming => Releases => Topic started by: Spy on October 03, 2010, 08:09:44 PM



Title: Permutation Algorithm
Post by: Spy on October 03, 2010, 08:09:44 PM
Hey all,

Today my friend asked me to brute-force a password protected one-note document. I stupidly suggested that we write a piece of code that creates permutations for every letter in the alphabet and all Arabic numbers (0-9). After I actually finished the code we realized that it would generate around 3.71993327 × 10^41 (or 36 factorial) permutations which is a ridiculous amount. We later decided to use a mutational algorithm based on a dictionary (I can post that code as well if anyone wants). Anyway, I just thought that this script might be beneficial to anyone that wants to get into permutations. It's loosely based off of a script I saw floating around a while ago. Enjoy!

Code:
import os
syntax = '' #syntax for one-note goes in this string
alphabet = list('abcdefghijklmnopqrstuvwxyz1234567890')
numbers = range(1,37)
def xcombinations(items, n):
    if n==0:
  yield []
    else:
  for i in xrange(len(items)):
    for cc in xcombinations(items[:i]+items[i+1:],n-1):
    yield [items[i]]+cc
def xpermutations(items):
    return xcombinations(items, len(items))
for n in numbers:
    for c in xcombinations(alphabet,n):
  send = syntax + ''.join(c)
  os.system(send)
  print send