Jul-19-2017, 07:32 PM
I am trying to create a caesar shift dis-cipher but this error keeps coming up.
What am I doing wrong?
caesar code: "g fmnc wms bgblr rpylqjyrc gr zw fylb rfyrq ufyr amknsrcpq ypc dmp bmgle gr gl zw fylb gq glcddgagclr ylb rfyrq ufw rfgq rcvr gq qm jmle sqgle qrpglekyicrpylq gq pcamkkclbcb lmu ynnjw ml rfc spj"
error message: Traceback (most recent call last):
File "F:\Computing Work\Python\Program content page.py", line 50, in <module>
julius()
File "F:\Computing Work\Python\Program content page.py", line 35, in julius
cracked=num_to_let(a[counter],z)
File "F:\Computing Work\Python\Program content page.py", line 21, in num_to_let
g = z + let_to_num(num)
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
What am I doing wrong?
caesar code: "g fmnc wms bgblr rpylqjyrc gr zw fylb rfyrq ufyr amknsrcpq ypc dmp bmgle gr gl zw fylb gq glcddgagclr ylb rfyrq ufw rfgq rcvr gq qm jmle sqgle qrpglekyicrpylq gq pcamkkclbcb lmu ynnjw ml rfc spj"
error message: Traceback (most recent call last):
File "F:\Computing Work\Python\Program content page.py", line 50, in <module>
julius()
File "F:\Computing Work\Python\Program content page.py", line 35, in julius
cracked=num_to_let(a[counter],z)
File "F:\Computing Work\Python\Program content page.py", line 21, in num_to_let
g = z + let_to_num(num)
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
#Variables y=0 #Variable for while loop alphabet=["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "] #function takes a 2 numbers then def power(): a=int(input("Enter number: ")) b=int(input("Enter power: ")) print(a**b) #Takes a letter and gives you the numerical postion in the alphabet def let_to_num(x): for i in range(0,26): if(x==alphabet[i]): c=int(i) return(int(c)) else: print("nonono") #Takes a number and a shift value and performs a calculation to attain the postion of the result in the alphabet def num_to_let(num, z): g = 0 g = z + let_to_num(num) return(alphabet[g]) #Performs a caesar shift decryption def julius(): z=0 counter=1 a=str(input("Enter sentence: ")) b=str(input("Enter 1st letter: ")) c=str(input("Enter 2nd letter: ")) letA=let_to_num(b) letB=let_to_num(c) z=letA-letB cracked=[] for i in range(0,len(a)): cracked=num_to_let(a[counter],z) counter+=1 print(cracked) #Menu loop while(y==0): ans=int(input("***Programs***\n 1) Powerer\n 2) Caesar Cipher")) if(ans==1): power() elif(ans==2): julius() else: print("3")