Hello, I'm trying to script a Caesar cipher with the key, I find this exercise too much for me at this moment! I just can't come up with an algorith to get this done. Please advise.

key = {'a':'n', 'b':'o', 'c':'p', 'd':'q', 'e':'r', 'f':'s', 'g':'t', 'h':'u',
       'i':'v', 'j':'w', 'k':'x', 'l':'y', 'm':'z', 'n':'a', 'o':'b', 'p':'c',
       'q':'d', 'r':'e', 's':'f', 't':'g', 'u':'h', 'v':'i', 'w':'j', 'x':'k',
       'y':'l', 'z':'m', 'A':'N', 'B':'O', 'C':'P', 'D':'Q', 'E':'R', 'F':'S',
       'G':'T', 'H':'U', 'I':'V', 'J':'W', 'K':'X', 'L':'Y', 'M':'Z', 'N':'A',
       'O':'B', 'P':'C', 'Q':'D', 'R':'E', 'S':'F', 'T':'G', 'U':'H', 'V':'I',
       'W':'J', 'X':'K', 'Y':'L', 'Z':'M'}
def caesar_cipher(input):
  got= ''
  # and I'm knocked out. help ! help !

Recommended Answers

All 4 Replies

Member Avatar for Rahul47

I think what you are trying to do is Rotate 13 characters ahead, i.e ROT-13.
Here are the steps to follow:
1) Convert PLAIN TEXT to ASCII codes.
2) Add 13 to ASCII Code.
3) Convert incremented ASCII Code to Characters.

For help on conversion of characters to ASCII refere to Official Python Documentation

We can help, but we cannot do your homework for you. Find the ciphered version of the word 'hello', then try to compute it with the dictionary.

thanks. and this is not my homework. it's an exercise that I follow to learn programming in Python.

In general ...

mydict = {
'a':'n', 'b':'o', 'c':'p', 'd':'q', 'e':'r', 'f':'s', 'g':'t', 'h':'u',
'i':'v', 'j':'w', 'k':'x', 'l':'y', 'm':'z', 'n':'a', 'o':'b', 'p':'c',
'q':'d', 'r':'e', 's':'f', 't':'g', 'u':'h', 'v':'i', 'w':'j', 'x':'k',
'y':'l', 'z':'m', 'A':'N', 'B':'O', 'C':'P', 'D':'Q', 'E':'R', 'F':'S',
'G':'T', 'H':'U', 'I':'V', 'J':'W', 'K':'X', 'L':'Y', 'M':'Z', 'N':'A',
'O':'B', 'P':'C', 'Q':'D', 'R':'E', 'S':'F', 'T':'G', 'U':'H', 'V':'I',
'W':'J', 'X':'K', 'Y':'L', 'Z':'M'
}

text = "Hello!"

cipher_text = ""
for c in text:
    # look up dictionary value for key = c and build up cipher_text
    # if c is not a dictionary key use the original c
    if c in mydict.keys():
        cipher_text += mydict[c]
    else:
        cipher_text += c

print(cipher_text)  # result --> Uryyb!

To decode use the reversed dictionary.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.