-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaesar.py
32 lines (25 loc) · 1.09 KB
/
caesar.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
from helpers import rotate_character
def encrypt(text, rot):
return ''.join(rotate_character(char, rot) for char in text)
def main(shift, verbose, text):
msg = input('Type a message:\n') if text is None else text
while True:
try:
rot = int(input('Rotate by:\n')) if shift is None else shift
break
except ValueError:
print('error: the shift must be an integer, please try again')
continue
if verbose:
print('Encrypted message:')
print(encrypt(msg, rot))
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description='encrypt plaintext with Caesar cipher')
parser.add_argument('shift', type=int, nargs='?',
help='distance to shift character down alphabet')
parser.add_argument('-v', '--verbose', action='store_true', default=False,
help="increase output verbosity")
parser.add_argument('-t', '--text', help='plaintext to encrypt', dest='text')
args = parser.parse_args()
main(args.shift, args.verbose, args.text)