Exemplo n.º 1
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()
Exemplo n.º 2
0
# Type check cipher_functions.encrypt_letter
result = cipher_functions.encrypt_letter('A', 1)
assert isinstance(result, str) and len(result) == 1, \
    '''encrypt_letter should return a single character, but returned {0}''' \
    .format(type(result))


# Type check cipher_functions.decrypt_letter
result = cipher_functions.decrypt_letter('B', 1)
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), \
Exemplo n.º 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.
    """
    #####################################################################
    ##
    ##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)          
    .format(type(result))

# Type check cipher_functions.encrypt_letter
result = cipher_functions.encrypt_letter('A', 1)
assert isinstance(result, str) and len(result) == 1, \
    '''encrypt_letter should return a single character, but returned {0}''' \
    .format(type(result))

# Type check cipher_functions.decrypt_letter
result = cipher_functions.decrypt_letter('B', 1)
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))