Coud you write 2 programs for me in PYTHON please The first

Coud you write 2 programs for me in PYTHON please? The first program will be to encrypt a file the user will imput. The second will decrypt the encrypted file (MORE DETAILS BELOW). For each program could you seperate code into seperate functions and calling them in main? Also, can you make it so the user has to input the file from the users computer plaese??? Make the programs as simple as possible please.

Program 1: Vigenere Cipher Write a program named vigenerecipher.py that takes a file name FROM THE USER and a code word/phrase as arguments. Open the file FROM THE USER and uses the Vigenere cipher to encode the contents of the file according to the cipher. The program should output the cipher text into ‘filename’-cipher.txt where ‘filename’ was the original file name. For example, if the file’s name is message.txt the ciphered text would be saved in the message-cipher.txt The Vigenere cipher is polyalphabetic substitution cipher. It is variation of Caesar’s cipher where the alphabet is shifted by a fixed number of letters. For example, if the alphabet is shifted by eight, then the upshifted alphabet (first line) will map the following letters (second line):

ABCDEFGHIJKLMNOPQRSTUVWXYZ

IJKLMNOPQRSTUVWXYZABCDEFGH

The Vigenere cipher uses 26 alphabets that are each progressive shifted from 0 to 26. The code word provides an index into which one of the shifted alphabets will be used to cipher each letter of the clear text message into cipher text. For example, the clear text is “The eagle has landed” and the code word is “lime.” The above text would be ciphered to: Epq iloxi sie plvpio

Program 2: Vigenere De-cipher Write a program named vigeneredecipher.py that takes a file name and a code word/phrase as arguments. Open the file and use the Vigenere cipher to decode the contents of the file according to the cipher. The program should output the clear text into ‘filename’-clear.txt where ‘filename’ was the original file name. For example, if the input is message-cipher.txt the output of the program is saved in message-cipher-clear.txt

Solution

PROGRAM 1 vigenerecipher.py

import sys
filename=sys.argv[1]
codeword=sys.argv[2]

d={\'o\': 14, \'c\': 2, \'k\': 10, \'b\': 1, \'i\': 8, \'e\': 4,
\'a\': 0, \'u\': 20, \'z\': 25, \'d\': 3, \'v\': 21, \'x\': 23,
\'t\': 19, \'r\': 17, \'g\': 6, \'n\': 13, \'f\': 5, \'p\': 15,
\'m\': 12, \'q\': 16, \'j\': 9, \'w\': 22, \'s\': 18,
\'h\': 7, \'y\': 24, \'l\': 11}

f=open(filename,\'r\')
s=f.read()
s=s.strip()

f2=open(filename[:-4]+\'-cipher.txt\',\'w\')
alphabet=list(\'abcdefghijklmnopqrstuvwxyz\')
i=0
table=[]

for r in range(26):
    table.append([])
  
    for c in range(26):
      
        table[r].append(alphabet[i % len(alphabet)])
        i+=1
    i+=1

i=0
lm=[]
lk=[]
for c in s:
   if c==\' \':
       lm.append(\' \')
       lk.append(\' \')
   else:
       lm.append(c)
       lk.append(codeword[i])
       if i==(len(codeword)-1):
           i=0
       else:
           i+=1
enc=[]

for k ,p in zip(lk,lm):
    if k==\' \' and p==\' \':
        enc.append(\' \')
    else:
      
        r=d[k.lower()]
        c=d[p.lower()]
        if p.isupper():
            enc.append(table[c][r].upper())
        else:
            enc.append(table[c][r])
enc_txt=\'\'   
for c in enc:
    enc_txt=enc_txt+c


f2.write(enc_txt)
f2.close()


PROGRAM 2 vigeneredecipher.py

import sys
filename=sys.argv[1]
codeword=sys.argv[2]
de={\'o\': 14, \'c\': 2, \'k\': 10, \'b\': 1, \'i\': 8, \'e\': 4,
\'a\': 0, \'u\': 20, \'z\': 25, \'d\': 3, \'v\': 21, \'x\': 23,
\'t\': 19, \'r\': 17, \'g\': 6, \'n\': 13, \'f\': 5, \'p\': 15,
\'m\': 12, \'q\': 16, \'j\': 9, \'w\': 22, \'s\': 18,
\'h\': 7, \'y\': 24, \'l\': 11}

dd={\'14\': \'o\', \'2\': \'c\', \'10\': \'k\', \'1\':\'b\', \'8\': \'i\', \'4\': \'e\',
\'0\': \'a\', \'20\': \'u\', \'25\': \'z\', \'3\': \'d\', \'21\':\'v\', \'23\':\'x\',
\'19\': \'t\', \'17\': \'r\', \'6\':\'g\', \'13\':\'n\', \'5\':\'f\', \'15\':\'p\',
\'12\': \'m\', \'16\':\'q\', \'9\':\'j\', \'22\': \'w\', \'18\': \'s\',
\'7\': \'h\', \'24\': \'y\', \'11\':\'l\'}

f=open(filename,\'r\')
s=f.read()
s=s.strip()

f2=open(filename[:-4]+\'-clear.txt\',\'w\')
alphabet=list(\'abcdefghijklmnopqrstuvwxyz\')
i=0
table=[]

for r in range(26):
    table.append([])
  
    for c in range(26):
      
        table[r].append(alphabet[i % len(alphabet)])
        i+=1
    i+=1

i=0
enc_msg=[]
list_key=[]
for c in s:
   if c==\' \':
       enc_msg.append(\' \')
       list_key.append(\' \')
   else:
       enc_msg.append(c)
       list_key.append(codeword[i])
       if i==(len(codeword)-1):
           i=0
       else:
           i+=1

enc=[]

for k ,p in zip(list_key,enc_msg):
    if k==\' \' and p==\' \':
        enc.append(\' \')
    else:
                   
        l=table[de[k]]
            
        if p==\' \':
            enc.append(\' \')
        elif p.isupper():
            p=p.lower()
            ind=str(l.index(p))
          
            enc.append(dd[ind].upper())
        else:
            ind=str(l.index(p))
            enc.append(dd[ind])
      
dec_txt=\'\'   
for c in enc:
    dec_txt=dec_txt+c

f2.write(dec_txt)
f2.close()


SAMPLE OUTPUT:

running the program through command prompt

C:\\>py vigenerecipher.py input.txt lime

C:\\>py vigeneredecipher.py input-cipher.txt lime

INPUT.TXT contains

Hello World from Python Programming

INPUT-CIPHER.txt contains

Smxpz Eavwl rvzu Bcepar Azakciyqtvs

INPUT-CIPHER-CLEAR.TXT contains

Hello World from Python Programming

Coud you write 2 programs for me in PYTHON please? The first program will be to encrypt a file the user will imput. The second will decrypt the encrypted file (
Coud you write 2 programs for me in PYTHON please? The first program will be to encrypt a file the user will imput. The second will decrypt the encrypted file (
Coud you write 2 programs for me in PYTHON please? The first program will be to encrypt a file the user will imput. The second will decrypt the encrypted file (
Coud you write 2 programs for me in PYTHON please? The first program will be to encrypt a file the user will imput. The second will decrypt the encrypted file (

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site