0

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 !
4
Contributors
4
Replies
38
Views
2 Years
Discussion Span
Last Post by vegaseat
Featured Replies
  • 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 … Read More

  • 1

    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', … Read More

1

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

0

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.

Edited by Gribouillis

0

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

1

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.

Edited by vegaseat

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.