Ejemplo n.º 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)
Ejemplo n.º 2
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 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)
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)
Ejemplo n.º 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))
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 10
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_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
Ejemplo n.º 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.
    """
    # 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.
    
    >>>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)    
Ejemplo n.º 13
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 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.
    """
    
#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
Ejemplo n.º 15
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()

    msg_file_handle = open(MSG_FILENAME, 'r')
    msg_list = cipher_functions.read_messages(msg_file_handle)

    msg_file_handle.close()

    msg_oneline = cipher_functions.process_messages(deck, msg_list, MODE)

    for msg in msg_oneline:
        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 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)
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()
Ejemplo n.º 18
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
Ejemplo n.º 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])
    .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))

# 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))
Ejemplo n.º 21
0
# 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))


# Type check cipher_functions.read_messages
result = cipher_functions.read_messages(open('secret1.txt'))
assert isinstance(result, list), \
Ejemplo n.º 22
0
deck2 = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 3, 6, \
    9, 12, 15, 18, 21, 24, 27, 2, 5, 8, 11, 14, 17, 20, 23, 26]
x12a = cipher_functions.get_next_keystream_value(deck1)
x12b = cipher_functions.get_next_keystream_value(deck2)
if x12a == 3 and x12b == 11:
    print("get_next_keystream_value:", True)
else:
    print("get_next_keystream_value:", False)
    print("got:", x12a)
    print("expected:", 3)
    print("got:", x12b)
    print("expected:", 11)

deck1 = [6, 2, 3, 4, 1, 5]
deck2 = [6, 2, 3, 4, 1, 5]
x13a = cipher_functions.process_messages(deck1, ['ABC'], 'e')
x13b = cipher_functions.process_messages(deck2, ['DCD'], 'd')
if x13a == ['DCD'] and x13b == ['ABC']:
    print("process_messages:", True)
else:
    print("process_messages:", False)
    print("got:", x13a)
    print("expected:", ['DCD'])
    print("got:", x13b)
    print("expected:", ['ABC'])

deck1 = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 3, 6, \
    9, 12, 15, 18, 21, 24, 27, 2, 5, 8, 11, 14, 17, 20, 23, 26]
deck2 = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 3, 6, \
    9, 12, 15, 18, 21, 24, 27, 2, 5, 8, 11, 14, 17, 20, 23, 29]
x14a = cipher_functions.is_valid_deck(deck1)
Ejemplo n.º 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)