def crackIt(): # Get the text from the ptext box T = ctext.get("1.0", "end")[:-1] T, pos, char, case = saveFormat(T) R = int(rounds.get("1.0", "end")[:-1]) tx = substitutionCracker(T, R) # Blank the ctext box then put the text in it ptext.delete("1.0", "end") ptext.insert("insert", restoreFormat(tx, pos, char, case))
def dec(): # Get the text from the ptext box T = ptext.get("1.0","end")[:-1] # Get the key from the key box K = key.get("1.0","end")[:-1] K = K.replace(" ","") K = K.upper() K = K.split(",") # Get the selected cipher C = cipher.get() # Get the formatting rule F = form.get() if C == "Type IV": if len(K) != 3: ctext.insert("insert","Quagmire IV requires three keywords") else: if len(K) != 2: ctext.insert("insert","Quagmire I, II, and III require two keywords") T, pos, char,case = saveFormat(T) # We use a dictionary as basically a as a switch statement # They keys are the names of the cipher while the values are the cipher # functions that we imported cipherDict = {"Type I": quagmire1, "Type II": quagmire2, "Type III": quagmire3, "Type IV": quagmire4} # Blank the ctext box ctext.delete("1.0","end") # Try encrypting try: tx = cipherDict[C](T,K,decode=True) except Exception as e: ctext.insert("insert",str(e)) if F == 1: ctext.insert("insert",restoreFormat(tx, pos, char,case)) else: ctext.insert("insert",tx)
def vernam(text, key, decode=False): text, pos, char, case = saveFormat(text, "01") bits = LFSR(key[0], key[1], 16, bits=True) out = [] for t, b in zip(text, bits): if t == " ": out.append(" ") continue if b == 0: out.append(t) else: if t == "0": out.append("1") else: out.append("0") ftext = restoreFormat("".join(out), pos, char, case) return ftext
def dec(): # Get the text from the ptext box T = ptext.get("1.0", "end")[:-1] # Get the key from the key box K = key.get("1.0", "end")[:-1] K = K.upper() # Get the selected cipher C = cipher.get() # Get the formatting rule F = form.get() T, pos, char, case = saveFormat(T) # We use a dictionary as basically a as a switch statement # They keys are the names of the cipher while the values are the cipher # functions that we imported cipherDict = { "vigenere": vigenere, "beaufort": beaufort, "autokey": autokey, "playfair": playfair, "substitution": substitution } # Blank the ctext box ctext.delete("1.0", "end") # Try encrypting try: tx = cipherDict[C](T, K, decode=True) except Exception as e: ctext.insert("insert", str(e)) if F == 1: ctext.insert("insert", restoreFormat(tx, pos, char, case)) else: ctext.insert("insert", tx)