# Shift cipher decryption. Call for each letter ciphertext # # c - the ciphertext letter (uppper case) # k - the key, the number of letters to shift by # return the plaintext letter (lower case) def decrypt(c, k): p = (ord(c) - k - ord('A')) % 26 if (p < 0): p += 26 return chr(p + ord('a')) # this variable holds the input ciphertext # use raw_input for python 2 ciphertext = input("Enter in the ciphertext: ") for k in range(1, 26): print("key = " + str(k)) plaintext = "" for i in range(len(ciphertext)): if ord(ciphertext[i]) >= ord('A') and ord(ciphertext[i]) <= ord('Z'): plaintext += decrypt(ciphertext[i], k) else: plaintext += ciphertext[i] print(plaintext) # use print("") for python 2 print() # test text: # KYV JYZWK TZGYVI ZJ RCJF BEFNE RJ KYV TRVJRI TZGYVI, RWKVI ALCZLJ TRVJRI, NYF IVGLKVUCP LJVU KYV TZGYVI KF GRJJ DVJJRXVJ KF YZJ KIFFGJ ULIZEX YZJ DZCZKRIP TRDGRZXEJ ZE XRLC. EFKV KYRK KYV TRVJRI TZGYVI ZJ VRJZCP TIRTBVU SP KYV SILKV-WFITV RKKRTB.