3

For example, if I were to apply 4 shifts to "breakzone" than it would be intended to be like:

"b" would be shifted by 2 characters "r" would be shifted by 3 characters "e" would be shifted by 4 characters "a" would be shifted by 5 characters and then we'd start back at the initial shift amount at 2: "k" would be shifted by 2 characters etc...

here's what I have so far:

statement = input("Enter string: ")
multiple_shifts = input(int("Enter shift amounts: "))
def caesar(word,multiple_shifts):
    for ch in statement:
        if ch = statement[0]:

I know it's not much but I'm definitely lost and any help is appreciated. Not asking you to "write my own code" just point me in the right direction so I'd greatly appreciate any knowledge of this subject.

Rad'Val
  • 8,895
  • 9
  • 62
  • 92
Chris
  • 35
  • 4
  • "cipher in which the letters of the alphabet are substituted by a different letter that have a fixed distance to the original letter." if each letter shifts by a different amount wouldn't be a caesar cipher? – Tadhg McDonald-Jensen Apr 09 '17 at 00:41
  • Yeah I'm just not sure how I'd go assigning these shifts to the letters – Chris Apr 09 '17 at 00:44

1 Answers1

2

Here's a very crude implementation:

import sys

def caesar(word, shifts):
    word_list = list(word.lower())
    result = []
    s = 0
    for c in word_list:
        next_ord = ord(c) + s + 2
        if next_ord > 122:
            next_ord = 97

        result.append(chr(next_ord))
        s = (s + 1) % shifts
    return "".join(result)

if __name__ == "__main__":
    print(caesar("breakzone", 4))

If you wonder what's with 122 and 97, those are the Unicode values for lower case z and a. You could easily change the above to support full Unicode (e.g. be able to encode H3ll0 for example). Here's a Unicode chart that might help you.

Rad'Val
  • 8,895
  • 9
  • 62
  • 92