def main(fname=None, key=None, mode=None):
    if fname == None:
        fname = input("Enter Filename: ")
    if key == None:
        key = int(input("Enter Key: "))
    if mode == None:
        mode = int(input("Encrypt(1) or Decrypt(0): "))

    if mode:
        mode = "encrypt"
    else:
        mode = "decrypt"

    outputFilename = fname + ".enc"

    if not os.path.exists(fname):
        print('The file "%s" does not exist. Quitting...' % fname)
        sys.exit()

    if os.path.exists(outputFilename):
        print('This will overwrite the file "%s". (C)ontinue or (Q)uit? ' % outputFilename)
        response = input("> ")
        if not response.lower().startswith("c"):
            sys.exit()

    with open(fname, "r") as fileObj:
        content = fileObj.read()

    print("%sing..." % mode.title())

    startTime = time.time()

    if mode == "encrypt":
        translated = transpositionCipher.encrypt(key, content)
    elif mode == "decrypt":
        translated = transpositionCipher.decrypt(key, content)
    totalTime = round(time.time() - startTime, 2)
    print("%sion time: %s seconds" % (mode.title(), str(totalTime)))

    with open(outputFilename, "w") as outputFileObj:
        outputFileObj.write(translated)

    print('Done %sing "%s" (%s characters).' % (mode, fname, str(len(content))))
    print('%sed file is "%s".' % (mode.title(), outputFilename))
def main():
    global NUM_TESTS, SEED
    random.seed(SEED)

    for i in range(NUM_TESTS):
        message = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' * random.randint(4, 40)

        message = list(message)
        random.shuffle(message)
        message = ''.join(message)
        print('Test #%i: "%s..."' % (i+1, message[:50]))

        for key in range(1, len(message)):
            encrypted = transpositionCipher.encrypt(key, message)
            decrypted = transpositionCipher.decrypt(key, encrypted)

            if message != decrypted:
                print('Mismatch with key %i and message %s.' % (key, message))
                print(decrypted)
                sys.exit()

    print('transposition cipher test passed.')
def roundFunction(message, sKey, nKey, rnd):
    message = caesarCipher2.encryptMessage(nKey, message)
    message = transpositionCipher.encrypt(message, rnd)
    message = vigenereCipher.decryptMessage(sKey, message)
    return message