def my_form_post(): text = request.form['text'] userinput = text.upper() selected = [] substitutionresult = "N/A" columntransresult = "N/A" if request.form.get('substitution'): selected.append("substitution") print(regex.sub('', userinput), "HE") substitutionresult = annealing_decryption.anneal( regex.sub('', userinput), key, ciphertype, "swap", "") if request.form.get('vigenere'): selected.append("vigenere") if request.form.get('columntrans'): selected.append('columntrans') columns = request.form['columns'] colno = 0 if columns == "": colno = 0 else: colno = int(columns) if colno > 1: columntransresult = transpos(regex.sub('', userinput), colno) else: for x in range(2, 21): columntransresult = transpos(regex.sub('', userinput), x) print(json.dumps(selected)) msg = Message('Your Decoded Message from Tech Support', sender='*****@*****.**', recipients=['*****@*****.**']) msg.html = 'Substitution Result: ' + substitutionresult + '<br><br>Column Transposition: ' + columntransresult mail.send(msg) return render_template("result.html", substitutionresult=substitutionresult, columntransresult=columntransresult)
def my_form_post(): text = request.form['text'] userinput = text.upper() selected = [] substitionresult = "" columntransresult = "" if request.form.get('substition'): selected.append("substition") print(regex.sub('', userinput), "HE") substitionresult = annealing_decryption.anneal( regex.sub('', userinput), key, ciphertype, "swap", "") if request.form.get('vigenere'): selected.append("vigenere") if request.form.get('columntrans'): selected.append('columntrans') columns = request.form['columns'] colno = 0 if columns == "": colno = 0 else: colno = int(columns) if colno > 1: columntransresult = transpos(regex.sub('', userinput), colno) else: for x in range(2, 21): columntransresult = transpos(regex.sub('', userinput), x) print(json.dumps(selected)) return render_template("result.html", substitionresult=substitionresult, columntransresult=columntransresult)
def transpos(text, colno): key = str(math.floor(1234567890 / (10**(10 - colno)))) return (annealing_decryption.anneal(text, key, "transposition", "swap", ""))
def vigenere(text, keylen): key = "A" * keylen print(annealing_decryption.anneal(text, key, "vigenere", "rand", ""))
def substitutionsolver(userinput): regex = re.compile('[^A-Z]') print( annealing_decryption.anneal(regex.sub('', userinput), key, ciphertype, "swap", ""))
import annealing_decryption import re import string key = string.ascii_uppercase ciphertype = "substitution" userinput = input("Enter encoded text:\n").upper() print(userinput) regex = re.compile('[^A-Z]') print(regex.sub('', userinput)) print( annealing_decryption.anneal(regex.sub('', userinput), key, ciphertype, "swap", ""))