“Sage code: Cesar’s parchment manuscript” (1_3.sage) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def Caesar(message,n):

    print 'This program will encode your messages using a Caesar Cipher'
    print
    codedMessage = ""
    for ch in message:
        if 65<=ord(ch)<=90:
            newChar = ord(ch)+n
            if (newChar > 90):
                newChar = newChar-26
            if (newChar < 65):
                newChar = newChar+26
            codedMessage = codedMessage + chr(newChar)
        elif 97<=ord(ch)<=122:
            newChar = ord(ch)+n
            if (newChar > 122):
                newChar = newChar-26
            if (newChar < 97):
                newChar = newChar+26
            codedMessage = codedMessage + chr(newChar)
        else:
            codedMessage = codedMessage + chr(ord(ch))
    print "The coded message is:", codedMessage

Caesar('HFJXFW BTZQI MFAJ GJJS UWTZI TK DTZ!',-5)
> This program will encode your messages using a Caesar Cipher

> The coded message is: CAESAR WOULD HAVE BEEN PROUD OF YOU!

Caesar('Caesar WOULD HAVE BEEN PROUD OF YOU!',5)
> This program will encode your messages using a Caesar Cipher

> The coded message is: Hfjxfw BTZQI MFAJ GJJS UWTZI TK DTZ!

Caesar('The quick brown fox jumps over the lazy dog ... ',17)
> This program will encode your messages using a Caesar Cipher

> The coded message is: Kyv hlztb sifne wfo aldgj fmvi kyv crqp ufx ...

Caesar('Kyv hlztb sifne wfo aldgj fmvi kyv crqp ufx ... ',-17)
> This program will encode your messages using a Caesar Cipher

> The coded message is: The quick brown fox jumps over the lazy dog ...

As an illustration, you shall try the output produced for the following entries:

  Caesar('HJXFW FZWFNY JYJ HTSYJSY IJ ATZX!',-5)