# # Solution to Schmoocon 2011 Crypto Challenges - Challenge 2 # by LarsH and kaliman (First Blood in 25 minutes, yay:) # # The challenge was to create a valid (integer) key for our team email and send in. # # A program that created a string from an integer by rotating a few strings was given. # Basically, generatedString[i] = rotor_i [ key % len(rotor_i) ] # # The character at position i in the string generated from key k will be unchanged for all keys (k + n*len(rotor_i)) for any integer n. # No characters will change if the product of all rotor lengths are added to the key. # Only the character at position i will change if the product of all rotor lengths except rotor i is added to the key. # # Iterative solving one character at a time by starting with key 0 and adding the product of the other rotor lengths until reaching the correct character. # As there was an upper limit on the key (which happen to be the product of all rotor lengths) the key addition was done modulus the limit. # name = "kali@GITS1" rotor = [" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ`abcdefghijklmnopqrstuvwxyz{|}~1akuEOY"\ , " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ`abcdefghijklmnopqrstuvwxyz{|}~2blvFPZ9hqz"\ , " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ`abcdefghijklmnopqrstuvwxyz{|}~3cmwGQ10irAIQ"\ , " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ`abcdefghijklmnopqrstuvwxyz{|}~4dnxHR2ajsBJRY6cj"\ , " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ`abcdefghijklmnopqrstuvwxyz{|}~5eoyIS3bktCKSZ7dkqw"\ , " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ`abcdefghijklmnopqrstuvwxyz{|}~6fpzJT4cluDLT18elrxCHMR"\ , " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ`abcdefghijklmnopqrstuvwxyz{|}~7gqAKU5dmvEMU29fmsyDINSW159cgkoswAEIM"\ , " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ`abcdefghijklmnopqrstuvwxyz{|}~8hrBLV6enwFNV30gntzEJOTX260dhlptxBFJNQTWZ"\ , " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ`abcdefghijklmnopqrstuvwxyz{|}~9isCMW7foxGOW4ahouAFKPUY37aeimquyCGKORUX13579ac"\ , " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ`abcdefghijklmnopqrstuvwxyz{|}~0jtDNX8gpyHPX5bipvBGLQVZ48bfjnrvzDHLPSVY24680bdef"] lens = map(len, rotor) mod = 1 for q in lens: mod = mod*q os = [ (mod / a) for a in lens] chars = [a.find(b) for a,b in zip(rotor, name)] s = 0 for a, l, char in zip(os, lens, chars): while (s % l) != char: s = (s + a) % mod print name, s