-2

I'm using Python 3 to create a brute-force Vigenere decipher-er. Vigenere codes are basically adding strings of letters together.

The way I want my code to work is the user puts in however any keys they want (this bit's done), the letters are turned into their numbers (also done) then it adds every pair of keys together (working on this, also what I need help with) and prints out the two keys and what they added to.

To do this, I need to be able to keep track of which pairs of keys have been added together. How can I do this?

BTW, my current code is this. I'm doing this both fro the decoding and the programming practice, so I really just want the way to keep track of added key pairs, not the whole program.

#defines start variables
import math
alph = "abcdefghijklmnopqrstuvwxyz"
keyqty = int(input("how many keys?"))
listofkeys = []
listofindex = []
timer = 0

#gets keys
while True:
    if timer >= keyqty:
        break
    else:
        pass
    listofkeys.append(input("key: ").lower())
    timer += 1
tempkey = ""

#blank before key 
for item in listofkeys:
    listofindex.append("")
    for letter in item:
        listofindex.append(alph.find(letter)

timer = 0
newkey = False
key1index = []
key2index = []
endex = []
printletter = ""
doneadds = []

Obviously, it still needs some other work, but some help would be appreciated.

imtired
  • 11
  • 3

1 Answers1

1

You can either use a set for fast lookup (amortized constant time).

tried = set()
for ...
   if word not in tried:
       try()
       tried.add(word)

or use itertools.product() to generate your trials without the need of keeping track of the already tried ones.

for password in itertools.product(alph, repeat=keyqty):
   try(password)
abc
  • 11,579
  • 2
  • 26
  • 51