transposition cipher encrypt decrypt file Algorithm

The transposition cipher is a classic encryption algorithm that works by rearranging the characters of a plaintext message into a new order, creating the ciphertext. This encryption method is based on the concept of transposition, which means shifting the positions of the characters in the plaintext. The transposition cipher operates on a fixed-size block of text, and the rearrangement pattern is determined by a secret key, known only to the sender and the recipient. The strength of the transposition cipher lies in the large number of possible permutations that can be created from a given key, making it challenging for an attacker to decipher the encrypted message without the correct key. To decrypt the ciphertext, the recipient applies the inverse of the transposition process, using the same secret key. This involves reordering the characters in the ciphertext back to their original positions in the plaintext. The transposition cipher's simplicity makes it easy to implement in software, and it can be combined with other encryption algorithms to enhance security. However, on its own, the transposition cipher is vulnerable to frequency analysis, as the frequency of individual characters remains unchanged between the plaintext and the ciphertext. To counter this, the transposition cipher is often used in conjunction with substitution ciphers, forming a more secure encryption technique known as a product cipher.
import os
import sys
import time

import transposition_cipher as transCipher


def main():
    inputFile = "Prehistoric Men.txt"
    outputFile = "Output.txt"
    key = int(input("Enter key: "))
    mode = input("Encrypt/Decrypt [e/d]: ")

    if not os.path.exists(inputFile):
        print("File %s does not exist. Quitting..." % inputFile)
        sys.exit()
    if os.path.exists(outputFile):
        print("Overwrite %s? [y/n]" % outputFile)
        response = input("> ")
        if not response.lower().startswith("y"):
            sys.exit()

    startTime = time.time()
    if mode.lower().startswith("e"):
        with open(inputFile) as f:
            content = f.read()
        translated = transCipher.encryptMessage(key, content)
    elif mode.lower().startswith("d"):
        with open(outputFile) as f:
            content = f.read()
        translated = transCipher.decryptMessage(key, content)

    with open(outputFile, "w") as outputObj:
        outputObj.write(translated)

    totalTime = round(time.time() - startTime, 2)
    print(("Done (", totalTime, "seconds )"))


if __name__ == "__main__":
    main()

LANGUAGE:

DARK MODE: