-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoving.py
85 lines (63 loc) · 1.99 KB
/
moving.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File: moving.py
# Author: Simon Chu
# Date: 2/22/17
# Purpose: encode and decode a sentence
# moving characters 13 places.
def main():
print()
print("Program to encode and decode a sentence")
print("moving characters 13 places.")
print("You will be asked to enter a sentence.")
print("Written by Simon Chu.")
print()
sentence = input("Enter a sentence: ")
print()
print() # for turnin
# encode the sentence
cipherText = ""
for ch in sentence:
outChar = ch
# for lowercase letters
if ch >= "a":
if ch <= "z":
outChar = chr(ord(ch) + 13)
if outChar > "z":
outChar = chr(ord(ch) - 13)
if outChar < "a":
outChar = chr(ord(ch) + 13)
# for uppercase letters
if ch >= "A":
if ch <= "Z":
outChar = chr(ord(ch) + 13)
if outChar > "Z":
outChar = chr(ord(ch) - 13)
if outChar < "A":
outChar = chr(ord(ch) + 13)
cipherText = cipherText + outChar
# decode the sentence
decodeText = ""
for ch in cipherText:
outChar = ch
# for lowercase letters
if ch >= "a":
if ch <= "z":
outChar = chr(ord(ch) + 13)
if outChar > "z":
outChar = chr(ord(ch) - 13)
if outChar < "a":
outChar = chr(ord(ch) + 13)
# for uppercase letters
if ch >= "A":
if ch <= "Z":
outChar = chr(ord(ch) + 13)
if outChar > "Z":
outChar = chr(ord(ch) - 13)
if outChar < "A":
outChar = chr(ord(ch) + 13)
decodeText = decodeText + outChar
# print results
print("Original sentence:", sentence)
print("Encoded version: ", cipherText)
print("Decoded version: ", decodeText)
print()
main()