from browser import document def arrcomb(arr1, arr2, c1, c2, c3): if len(arr1) == 0: arr1 = [0] if len(arr2) == 0: arr2 = [0] biggest = max(len(arr1), len(arr2)) smaller = min(len(arr1), len(arr2)) v = [ (c1*arr1[i%len(arr1)]+c2*arr2[i%len(arr2)]+c3)%26 for i in range(biggest) ] return v def a2w(aaa): return ''.join([chr(97+aaa[i]) for i in range(len(aaa))]) def cipher(ev): aval = document["inpa"].value.lower() bval = document["inpb"].value.lower() alen = len(aval) blen = len(bval) arra = [ord(c)-97 for c in aval] arrb = [ord(c)-97 for c in bval] # array time m = min(alen,blen) apb = a2w(arrcomb(arra, arrb, 1, 1, 0)) atb = a2w(arrcomb(arra, arrb, 1, -1, 0)) bta = a2w(arrcomb(arra, arrb, -1, 1, 0)) ccc = a2w(arrcomb(arra, arrb, int(document["ca"].value), int(document["cb"].value), int(document["cc"].value))) document["aplusb"].innerHTML = ''+apb[0:m]+''+apb[m:] document["atakeb"].innerHTML = ''+atb[0:m]+''+atb[m:] document["btakea"].innerHTML = ''+bta[0:m]+''+bta[m:] document["comb"].innerHTML = ''+ccc[0:m]+''+ccc[m:] document.bind("keyup", cipher) document.bind("keydown", cipher)