Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- #recieve sentence and shift from user
- x = input("Please enter a sentence to encrypt:\n")
- shift = int(input("Please enter the size of the shift:\n"))
- #add encrypted text to new list
- txt = []
- for i in range(len(x)):
- if x[i] == '#':
- txt.append('*')
- continue
- elif i == len(x)-1 and x[i] == '!':
- continue
- elif x[i] == '?':
- continue
- #
- elif (ord('A') <= ord(x[i]) <= ord('Z')) or (ord('a') <= ord(x[i]) <= ord('z')):
- if ord(x[i]) % 2 == 0:
- y = ord(x[i])
- for j in range(0,shift):
- if y == ord('z') or y == ord('Z'):
- y = ord('a')
- else:
- y += 1
- txt.append(chr(y).lower())
- else:
- y = ord(x[i])
- for j in range(0,shift):
- if y == ord('a') or y == ord('A'):
- y = ord('Z')
- else:
- y -= 1
- txt.append(chr(y).upper())
- else:
- txt.append(x[i])
- print("".join(txt))
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement