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)
示例#2
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)
示例#3
0
        .format(type(item))


# 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))
for item in result:
    assert isinstance(item, str), \
        '''read_messages should return a list of str, but returned a list of {0}'''\
        .format(type(item))


# Type check cipher_functions.is_valid_deck
result = cipher_functions.is_valid_deck([1, 2, 3])
assert isinstance(result, bool), \
    '''is_valid_deck should return a bool, 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))
for item in result:
    assert isinstance(item, int), \
        '''read_deck should return a list of int, but returned a list of {0}'''\
        .format(type(item))
示例#4
0
    assert isinstance(item, str), \
        '''process_messages should return a list of str, but returned a list of {0}'''\
        .format(type(item))

# Type check cipher_functions.read_messages
result = cipher_functions.read_messages(open('secret_message.txt'))
assert isinstance(result, list), \
    '''read_messages should return a list, but returned {0}''' \
    .format(type(result))
for item in result:
    assert isinstance(item, str), \
        '''read_messages should return a list of str, but returned a list of {0}'''\
        .format(type(item))

# Type check cipher_functions.is_valid_deck
result = cipher_functions.is_valid_deck([1, 2, 3])
assert isinstance(result, bool), \
    '''is_valid_deck should return a bool, but returned {0}''' \
    .format(type(result))

# Type check cipher_functions.read_deck
result = cipher_functions.read_deck(open('card_deck.txt'))
assert isinstance(result, list), \
    '''read_deck should return a list, but returned {0}''' \
    .format(type(result))
for item in result:
    assert isinstance(item, int), \
        '''read_deck should return a list of int, but returned a list of {0}'''\
        .format(type(item))

our_print("""
示例#5
0
    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)
x14b = cipher_functions.is_valid_deck(deck2)
if x14a == True and x14b == False:
    print("is_valid_deck:", True)
else:
    print("is_valid_deck:", False)
    print("got:", x14a)
    print("expected:", True)
    print("got:", x14b)
    print("expected:", False)