Example #1
0
def main():
    """ () -> NoneType

    Perform the encryption using the deck from file named DECK_FILENAME and
    the message from file named MSG_FILENAME. If MODE is 'e', encrypt;
    otherwise, decrypt.
    """

    prompt = 'Enter the name of the file that contains the card deck: '
    deck_file = open(get_valid_filename(prompt), 'r')
    deck = cipher_functions.read_deck(deck_file)
    deck_file.close()
    if not (cipher_functions.is_valid_deck(deck)):
        print('The supplied card deck is not a valid deck.')
        print('Encryption process stopping.')
        return

    prompt = 'Enter the name of the file that contains the message: '
    msg_file = open(get_valid_filename(prompt), 'r')
    messages = cipher_functions.read_messages(msg_file)
    msg_file.close()

    mode = get_encryption_mode()

    for msg in cipher_functions.process_messages(deck, messages, mode):
        print(msg)
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. Print the decrypted message to the screen.
    """
    # Open deck file handle
    message_file_handle = open(MSG_FILENAME, 'r')
    # Open message file handle
    deck_file_handle = open(DECK_FILENAME, 'r')
    # Retrieve the data from the message file handle
    messages_to_process = cipher_functions.read_messages(message_file_handle)
    # Retrieve the data from the deck file handle
    card_deck = cipher_functions.read_deck(deck_file_handle)
    # Close deck file handle
    message_file_handle.close()
    # Close message file handle
    deck_file_handle.close()
    # Process the messages retrieved
    processed_messages = (cipher_functions.process_messages(
        card_deck, messages_to_process, MODE))
    # Go through each processed message
    for new_message in processed_messages:
        # Outputs the processed message
        print(new_message)
Example #3
0
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.

    >>>main()
    EQFZSRTEAPNXLSRJAMNGAT
    GLCEGMOTMTRWKHAMGNME

    REQ: DECK_FILENAME != None
    REQ: MSG_FILENAME != None
    REQ: MODE == "e" or MODE == "d"
    """

    deck_file = open(DECK_FILENAME)
    message_file = open(MSG_FILENAME)

    deck = cipher_functions.read_deck(deck_file)
    messages = cipher_functions.read_messages(message_file)

    deck_file.close()
    message_file.close()

    translated = cipher_functions.process_messages(deck, messages, MODE)

    for a in translated:
        print(a)
def main():
    """ () -> NoneType

    Perform the encryption using the deck from file named DECK_FILENAME and
    the message from file named MSG_FILENAME. If MODE is 'e', encrypt;
    otherwise, decrypt.
    """

    prompt = 'Enter the name of the file that contains the card deck: '
    deck_file = open(get_valid_filename(prompt), 'r')
    deck = cipher_functions.read_deck(deck_file)
    deck_file.close()
    if not (cipher_functions.is_valid_deck(deck)):
        print('The supplied card deck is not a valid deck.')
        print('Encryption process stopping.')
        return

    prompt = 'Enter the name of the file that contains the message: '
    msg_file = open(get_valid_filename(prompt), 'r')
    messages = cipher_functions.read_messages(msg_file)
    msg_file.close()

    mode = get_encryption_mode()

    for msg in cipher_functions.process_messages(deck, messages, mode):
        print(msg)
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. Print the decrypted message to the screen.
    """
    # open a file with to use as a deck of cards
    file_deck = open(DECK_FILENAME, 'r')

    # open a file with the messages that need to be encrypted or decrypted
    file_message = open(MSG_FILENAME, 'r')

    # read the file with the deck of cards
    deck_cards = cipher_functions.read_deck(file_deck)

    # read the file with the messages
    messaged = cipher_functions.read_messages(file_message)

    # encrypt or decrypt the messages
    e_or_d_messages = (cipher_functions.process_messages(deck_cards, messaged,
                                                         MODE))

    # print each message per line
    for string_elements in e_or_d_messages:
        print(string_elements)
Example #6
0
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.
    """
    # gets the deck from cipher_functions.read_deck
    deck = cipher_functions.read_deck (DECK_FILENAME)
    # gets the messages from cipher_functions.read_messages
    messages = cipher_functions.read_messages (MSG_FILENAME)
    # prints the encrypted/decrypted message
    print (cipher_functions.process_messages (deck, messages, MODE))
Example #7
0
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 = cipher_functions.read_deck(open(DECK_FILENAME, 'r'))
    messages = cipher_functions.read_messages(open(MSG_FILENAME, 'r'))
    coded_messages = cipher_functions.process_messages(deck, messages, MODE)
    for i in coded_messages:
        print (i)
    pass
Example #8
0
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')
    message_file = open(MSG_FILENAME, 'r')
    card_list = cipher_functions.read_deck(deck_file)
    message_list = cipher_functions.read_messages(message_file)
    messages = cipher_functions.process_messages(card_list, message_list, MODE)
    for the_message in messages:
        print(the_message)
Example #9
0
def main():
    """ () -> NoneType

    Perform the encryption using the key from a file called KEY_FILENAME and
    the messages from a file called MSG_FILENAME. If MODE is 'e', encrypt;
    otherwise, decrypt.
    """
    inp1 = open(KEY_FILENAME, 'rt')
    inp2 = open(MSG_FILENAME, 'rt')
    # read the key and the text into a variable
    KEY = cipher_functions.read_deck(inp1)
    TEXT = cipher_functions.read_messages(inp2)
    # output the string of encrpted or decrypted message
    print (cipher_functions.process_messages(KEY, TEXT, MODE))
    pass
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.
    """
    open_deck = open(DECK_FILENAME, 'r')
    open(DECK_FILENAME, 'r')
    deck = (cipher_functions.read_deck(open_deck))
    open_file = open(MSG_FILENAME, 'r')
    open(MSG_FILENAME, 'r')
    message = (cipher_functions.read_messages(open_file))
    print (cipher_functions.process_messages(deck, message, MODE))
   

    pass
Example #11
0
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.
    """
    # Open both the deck and files for reading
    deck_filename = open(DECK_FILENAME, "r")
    msg_filename = open(MSG_FILENAME, "r")
    # Saves the deck after reading it
    deck = cipher_functions.read_deck(deck_filename)
    # Saves the messages after reading it
    msg = cipher_functions.read_messages(msg_filename)
    # This will print the decrypted or encrypted message that is in the file
    print(cipher_functions.process_message(deck, msg, MODE))
    # This will make sure that we close the file after we have opened it
    deck_filename.close()
    msg_filename.close()
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.
    """
    # Decrypts or encrypts the message in MSG_FILENAME with the deck of cards
    # specified in DECK_FILENAME. The program will encrypt or decrypt depending
    # on the MODE.
    out_list = cipher_functions.process_messages(cipher_functions.read_deck
                                                 (open(DECK_FILENAME, 'r')),
                                                 cipher_functions.read_messages
                                                 (open(MSG_FILENAME, 'r')),
                                                 MODE)

    # Print each element in the result list from encryption or decryption
    for each_element in out_list:
        print(each_element)
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.
    """
    # open deck file, read, close
    deckFile = open(DECK_FILENAME, 'r')
    deck = cipher_functions.read_deck(deckFile)
    deckFile.close()
    # open message file, read, close
    messageFile = open(MSG_FILENAME, 'r')
    messages = cipher_functions.read_messages(messageFile)
    messageFile.close()
    # process the messages
    toOutput = cipher_functions.process_messages(deck, messages, MODE)
    # print output, one message per line
    for line in toOutput:
        print (line)
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.
    
    >>>main()
    TCAVORYZALXEZDUJUFFFMHXXVPYHPYNRWWVHVJAHQ
    BQRAUFQEYXOVOTU
    """
    
    open_deck = open(DECK_FILENAME, 'r')
    card_deck = cipher_functions.read_deck(open_deck)
    open_messages = open(MSG_FILENAME, 'r')    
    messages = cipher_functions.read_messages(open_messages)
    processed = cipher_functions.process_messages(card_deck, messages, MODE)
    
    for encrypted_messages in processed:
        print(encrypted_messages)    
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.
    """
    
#Opens the files of deck and message for reading, converts the content into a 
#form comprehendable by the program using the read_deck and read_message
#functions, and then encrypts or decrypts the message and prints it.

    deck = open(DECK_FILENAME , 'r')
    message = open(MSG_FILENAME , 'r')
    processed_deck = cipher_functions.read_deck(deck)
    processed_msg = cipher_functions.read_messages(message)
    final_msg  = cipher_functions.process_messages(processed_deck , processed_msg , MODE)
    for msg in final_msg :
        print(msg)
    
    pass
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. Print the decrypted message to the screen.
    """
    # open the file of deck
    deck_file = open(DECK_FILENAME, "r")
    # get the deck of cards
    deck_cards = cipher_functions.read_deck(deck_file)
    # open the file of messages
    msg_file = open(MSG_FILENAME, "r")
    # get the list of messages
    messages_list = cipher_functions.read_messages(msg_file)
    # gets the new list of messages
    n_messages_list = cipher_functions.process_messages(deck_cards, \
                                                        messages_list, MODE)
    # print the new messages per line
    for message in n_messages_list:
        print(message)
Example #17
0
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_handle = open(DECK_FILENAME, 'r')      
    deck = cipher_functions.read_deck(deck_file_handle)
    deck_file_handle.close()
    
    print(deck)
    
    msg_file_handle = open(MSG_FILENAME, 'r')
    msg_list = cipher_functions.read_messages(msg_file_handle)
       
    msg_file_handle.close()    
    print(msg_list)
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.
    """
    # variable to open the deck
    deck_file = open(DECK_FILENAME, "r")
    # variable to open the message file
    message_file = open(MSG_FILENAME, "r")
    # sends the variables for the file and MODE to process_messages
    # and gets the decrypted/encrypted file (depending on mode)
    crypted_message = cipher_functions.process_messages(
        cipher_functions.read_deck(deck_file),
        cipher_functions.read_messages(message_file), MODE)
    # prints the elements of the crypted message, one per line
    for i in crypted_message:
        print(i)
    # closing the files
    deck_file.close()
    message_file.close()
Example #19
0
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. Print the decrypted message to the screen.
    REQ: A valid card_deck is a max of 26 cards and JOKER1 and JOKER2
    """
    # open the deck file
    file_deck = open(DECK_FILENAME, 'r')
    # read only the integer contents of the file
    read_deck = cipher_functions.read_deck(file_deck)
    # open the messages file
    file_messages = open(MSG_FILENAME, 'r')
    # Read the contents of the file as a list of messages.
    read_messages = cipher_functions.read_messages(file_messages)
    # If the mode is 'e' then encrypt. If the mode is 'd' then decrypt.
    encrypt_or_decrypt = cipher_functions.process_messages(
        read_deck, read_messages, MODE)
    # close the files
    file_deck.close()
    file_messages.close()
    for element in range(len(encrypt_or_decrypt)):
        print(encrypt_or_decrypt[element])
Example #20
0
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. Print the decrypted message to the screen.
    The function will open files and close files.
    The function will return nothing.
    """
    # open and read the messages file
    file_messages = open(MSG_FILENAME, 'r')
    messages = cipher_functions.read_messages(file_messages)
    # close the file
    file_messages.close()
    # open and read the cards file
    file_cards = open(DECK_FILENAME, 'r')
    deck_of_cards = cipher_functions.read_deck(file_cards)
    # close the file
    file_cards.close()
    # encrypt or decrypt based on cards, messages and MODE
    result = cipher_functions.process_messages(deck_of_cards, messages, MODE)
    # print the result
    print(result)
    return None
assert isinstance(result, str) and len(result) == 1, \
    '''decrypt_letter should return a single character, but returned {0}''' \
    .format(type(result))

# Type check cipher_functions.process_message
result = cipher_functions.process_message(sample_deck, 'ABC', 'e')
assert isinstance(result, str), \
    '''process_message should return a string, but returned {0}''' \
    .format(type(result))

# Type check cipher_functions.process_messages
result = cipher_functions.process_messages(sample_deck, ['A', 'B', 'C'], 'd')
assert isinstance(result, list), \
    '''process_messages should return a list, but returned {0}''' \
    .format(type(result))

# Type check cipher_functions.read_deck
result = cipher_functions.read_deck(open('deck1.txt'))
assert isinstance(result, list), \
    '''read_deck should return a list, but returned {0}''' \
    .format(type(result))

# Type check cipher_functions.read_messages
result = cipher_functions.read_messages(open('secret1.txt'))
assert isinstance(result, list), \
    '''read_messages should return a list, but returned {0}''' \
    .format(type(result))

# main is not typechecked because it acquires user-input
# It takes no parameters and returns None
Example #22
0
# Type check cipher_functions.process_message
result = cipher_functions.process_message(sample_deck, 'ABC', 'e')
assert isinstance(result, str), \
    '''process_message should return a string, but returned {0}''' \
    .format(type(result))


# Type check cipher_functions.process_messages
result = cipher_functions.process_messages(sample_deck, ['A', 'B', 'C'], 'd')
assert isinstance(result, list), \
    '''process_messages should return a list, but returned {0}''' \
    .format(type(result))


# Type check cipher_functions.read_deck
result = cipher_functions.read_deck(open('deck1.txt'))
assert isinstance(result, list), \
    '''read_deck should return a list, but returned {0}''' \
    .format(type(result))


# Type check cipher_functions.read_messages
result = cipher_functions.read_messages(open('secret1.txt'))
assert isinstance(result, list), \
    '''read_messages should return a list, but returned {0}''' \
    .format(type(result))


# main is not typechecked because it acquires user-input
# It takes no parameters and returns None
Example #23
0
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.
    """
    #####################################################################
    ##
    ##Test1 Encrypt
    ##
    #####################################################################
    d_file = open(DECK_FILENAME, 'r')
    m_file = open(MSG_FILENAME, 'r')
    deck = cipher_functions.read_deck(d_file)
    msg = cipher_functions.read_messages(m_file)
    result = ""
    result += cipher_functions.process_messages(deck, msg, MODE)
    print (result)
    #####################################################################
    ##
    ##Test2 decrypt
    ##
    #####################################################################
    d_file = open(DECK_FILENAME, 'r')
    deck = cipher_functions.read_deck(d_file)
    s_file = open("secret1.txt", 'r')
    s_msg = cipher_functions.read_messages(s_file)
    result = cipher_functions.process_message(deck, s_msg, 'd')
    print (result)
    #####################################################################
    ##
    ##Test3 decrypt
    ##
    #####################################################################
    d_file = open(DECK_FILENAME, 'r')
    deck = cipher_functions.read_deck(d_file)
    s_file = open("secret2.txt", 'r')
    s_msg = cipher_functions.read_messages(s_file)
    result = cipher_functions.process_messages(deck, s_msg, 'd')
    print (result)    
    ####################################################################
    #
    #Test4 decrypt
    #
    ####################################################################
    d_file = open(DECK_FILENAME, 'r')
    deck = cipher_functions.read_deck(d_file)
    s_file = open("secret3.txt", 'r')
    s_msg = cipher_functions.read_messages(s_file)
    result = cipher_functions.process_messages(deck, s_msg, 'd')
    print (result)    
    #####################################################################
    ##
    ##Test5 decrypt
    ##
    #####################################################################
    d_file = open(DECK_FILENAME, 'r')
    deck = cipher_functions.read_deck(d_file)
    s_file = open("secret4.txt", 'r')
    s_msg = cipher_functions.read_messages(s_file)
    result = cipher_functions.process_messages(deck, s_msg, 'd')
    print (result)    
    #####################################################################
    ##
    ##Test6 decrypt
    ##
    #####################################################################
    d_file = open(DECK_FILENAME, 'r')
    deck = cipher_functions.read_deck(d_file)
    s_file = open("secret5.txt", 'r')
    s_msg = cipher_functions.read_messages(s_file)
    result = cipher_functions.process_messages(deck, s_msg, 'd')
    print (result)    
    #####################################################################
    ##
    ##Test7 decrypt
    ##
    #####################################################################  
    d_file = open(DECK_FILENAME, 'r')
    deck = cipher_functions.read_deck(d_file)
    s_file = open("secret6.txt", 'r')
    s_msg = cipher_functions.read_messages(s_file)
    result = cipher_functions.process_message(deck, s_msg, 'd')
    print (result)
    #####################################################################
    ##
    ##Test8 decrypt
    ##
    ####################################################################  
    d_file = open(DECK_FILENAME, 'r')
    deck = cipher_functions.read_deck(d_file)
    s_file = open("secret7.txt", 'r')
    s_msg = cipher_functions.read_messages(s_file)
    result = cipher_functions.process_message(deck, s_msg, 'd')
    print (result)          
#message_decrypted_file_handle = open("message-decrypted.txt", 'r')
#message_decrypted_copy = message_decrypted_file_handle.readlines()
#message_decrypted_file_handle.close()
#print(message_decrypted_copy)
## Opens and outputs message-encrypted.txt
#message_decrypted_file_handle = open("message-encrypted.txt", 'r')
#message_decrypted_copy = message_decrypted_file_handle.readlines()
#message_decrypted_file_handle.close()
#print(message_decrypted_copy)
## Opens and outputs deck1.txt
#message_decrypted_file_handle = open("deck1.txt", 'r')
#message_decrypted_copy = message_decrypted_file_handle.readlines()
#message_decrypted_file_handle.close()
#print(message_decrypted_copy)
## Opens and outputs deck2.txt
#message_decrypted_file_handle = open("deck2.txt", 'r')
#message_decrypted_copy = message_decrypted_file_handle.readlines()
#message_decrypted_file_handle.close()
#print(message_decrypted_copy)
# Indexed loop: Opens and outputs all secret files 1 through 8
for text_file in range(1, 9):
    text_file_handle = open("secret" + str(text_file) + ".txt", 'r')
    text_file_copy = text_file_handle.readlines()

    # print(text_file_copy)
    print(test.read_messages(text_file_handle), text_file)
    # text_file_handle.close()

message_file_handle = open("secret" + str(4) + ".txt", 'r')
for line in message_file_handle.readlines():
    print(line.strip())