-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcipher_program.py
More file actions
32 lines (25 loc) · 1019 Bytes
/
cipher_program.py
File metadata and controls
32 lines (25 loc) · 1019 Bytes
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
"""
Encrypt or decrypt the contents of a message file using a deck of cards.
"""
import cipher_functions
DECK_FILENAME = 'deck1.txt'
MSG_FILENAME = 'message1.txt'
MODE = 'e' # 'e' for encryption, 'd' for decryption.
def main():
""" () -> NoneType
Perform the encryption using the deck from a file called DECK_FILENAME and
the messages from a file called MSG_FILENAME. If MODE is 'e', encrypt;
otherwise, decrypt.
"""
deck_file = open(DECK_FILENAME, 'r')
msg_file = open(MSG_FILENAME, 'r')
# Read the deck of cards from the deck_file, and the list of messages from
# the msg_file
deck = cipher_functions.read_deck(deck_file)
message_list = cipher_functions.read_messages(msg_file)
# Encrypt or decrypt the messages, depending on the mode, using the deck
new_messages_list = cipher_functions.process_messages(deck, message_list,
MODE)
for message in new_messages_list:
print(message)
main()