when you want to decrypt for example with shift 10 that means that you can encrypt it with shift 26 - 10. were you able to decode it? i hope so! send me a message back with the same offset!"įrom string import ascii_lowercase as alphabetĮncryption and decryption is a same stuff. "hey there! this is an example of a caesar cipher. muhu oek qrbu je tusetu yj? y xefu ie! iudt cu q cuiiqwu rqsa myjx jxu iqcu evviuj!"Įncrypted_messege += alphabet Messege = "xuo jxuhu! jxyi yi qd unqcfbu ev q squiqh syfxuh. muhu oek qrbu je tusetu yj? y xefu ie! iudt cu q cuiiqwu rqsa myjx jxu iqcu evviuj!". " uo jxuhu! jxyi yi qd unqcfbu ev q squiqh syfxuh. Print ("Your ciphertext is: ", cipherText1,"with negative shift of",encryption_shift)īutton1= Button(menu,text="encrypt",command=encrypt)īutton2= Button(menu,text="decrypt",command=decrypte)īutton3= Button(menu,text="exit",command=exit) StayInAlphabet1 = ord(c) - encryption_shift Print ("Your ciphertext is: ", cipherText,"with a shift of",shift)Įncryption=input("enter in your encrypted code")Įncryption_shift=int(input("enter in your encryption shift")) Shift = int(input("What is your shift? ")) PlainText = input("What is your plaintext? ") Table = string.maketrans(alphabet, shifted_alphabet) Shifted_alphabet = shifted_alphabet_lower + shifted_alphabet_upper
Shifted_alphabet_upper = alphabet_upper + alphabet_upperĪlphabet = alphabet_lower + alphabet_upper Shifted_alphabet_lower = alphabet_lower + alphabet_lower Shift %= 26 # Values greater than 26 will wrap around (Quoted from The Python Standard Library by Example). The function maketrans() creates translation tables that can be used with the translate method to change one set of characters to another more efficiently. The Python Standard Library defines a function maketrans() and a method translate that operates on strings. Placing cipherText before the start of the for loop will solve your problem.Īdditionally, there is an alternate approach to solving this problem using Python's Standard library. As pointed by others, you were resetting the cipherText in the iteration of the for loop.