Question

Write a python program: Ask for the encryption key. The key must be a list of...

  1. Write a python program:
  2. Ask for the encryption key.
    • The key must be a list of numbers between 0 and N-1, where N is the number of entries in the key's list; for example, 5,4,3,2,1,0 has six numbers, and each digit 0-5 appears in the list.
  3. Asks for a line of text to encrypt.
  4. Use the transposition key to transpose each chunk of N letters in input text.
    • If the input text is not a multiple of the key length, then pad the input with .. For example, if the key is 5,4,3,2,1,0 and the input is HelloMIS!, then add three . to make the input line a multiple of 6, like HelloMIS!...
    • Hint: You might slice batches of N characters out of the input string and loop over the indexes in the key to determine which characters to print out of each batch
  5. Output the encrypted result.
    • If the the key is 5,4,3,2,1,0 and the input text is HelloMIS!, then the output should be MolleH...!SI
    • Or, If the key is 4,3,2,1,0 and the input text is HelloMIS!, then the output should be olleH.!SIM
  • Show an error and exit the program if the encryption key does not have the numbers 0 though N-1 (where N is the number of values in the key).

An easy way to verify correct operation of the program is to use the encryption key 0, which should give the same string in the output as in the input. Another simple test is the encryption key 1,0, which will reverse each pair of input characters.

Examples of the program's run:

$ python transpose.py 
Enter key (comma-separated list of numbers)): 5,4,3,2,1,0
Enter text to encrypt: HelloMIS!
Encrypted text: MolleH...!SI

$ python transpose.py 
Enter key (comma-separated list of numbers)): 4,3,2,1,0
Enter text to encrypt: HellowMIS!
Encrypted text: olleH!SIMw

$ python transpose.py 
Enter key (comma-separated list of numbers)): 6,4,3,2,1,0
Error: key 6 is not valid (must be between 0 and 5)

$ python transpose.py 
Enter key (comma-separated list of numbers)): 4,3,2,1,0,0
Error: number 5 must be in the key

$ python transpose.py 
Enter key (comma-separated list of numbers)): 5,3,4,2,0,1
Enter text to encrypt: Our liberties we prize and our rights we will maintain.
Encrypted text: i lrOuetirbepe ws ae zrirou ndtghi rwe ws a mlilnaitin......

$ python transpose.py 
Enter key (comma-separated list of numbers)): 4,5,3,1,2,0
Enter text to encrypt: i lrOuetirbepe ws ae zrirou ndtghi rwe ws a mlilnaitin......
Encrypted text: Our liberties we prize and our rights we will maintain......
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#source code:


while(True):
   key=list(map(int, input("Enter key (comma-separated list of numbers)):").split(",")))
   new_list = key.copy()
   k=len(key)
   error=[]
   sub=key
   encrypt=""
   for i in range(len(key)):
       if i in sub:
           sub.remove(i)
       else:
           error.append(i)
      
   if(len(sub)==0 and len(error)==0):
       pass
   else:
       if(len(sub)==0 and len(error)!=0):
           print("Error: {} These elements are not present in the input range".format(error))
       elif(len(sub)!=0 and len(error)==0):
           print("Error: {} These elements outside given range".format(sub))
       else:
           print("Error: {} These elements are not ptreset in the input".format(error))
           print("Error: {} These elements outside given range".format(sub))
       continue
   enc=input("Enter text to encrypt: ")
   check=len(enc)
   if((check%k)==0):
       pass
   else:
       j=check-1
       while(j%k!=0):
           enc=enc+"."
           j=j+1
   new_txt=""
   string_list=[]
   for i in range(1,len(enc)+1):
       new_txt+=enc[i-1]
       if(i%k==0):
           string_list.append(new_txt)
           new_txt=""
       else:
           pass
   for i in range(len(string_list)):
       for j in range(len(new_list)):
           encrypt+=string_list[i][new_list[j]]
   print("Encrypted text: ",encrypt)
   break
  

      
      
  
          
      

#output:

#if you have any doubts comment below..if you like give thumbs up...

Add a comment
Know the answer?
Add Answer to:
Write a python program: Ask for the encryption key. The key must be a list of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MASM Assembly language -- Message Encryption Pgm You are to write a program to input a...

    MASM Assembly language -- Message Encryption Pgm You are to write a program to input a text and a key and encrypt the text. I will supply you an encryption key consisting of multiple characters. Use this key to encrypt and decrypt the plain text by XOR-ing each character of the key against a corresponding byte in the message. Repeat the key as many times as necessary until all plain text bytes are translated. Suppose, for example, the key were...

  • write in python Create a program that will ask the user for a list of integers,...

    write in python Create a program that will ask the user for a list of integers, all on one line separated by a slash. construct a list named "adj_numbers" which contains the users input numbers after subtracting 2 from each number. then print the resulting list. the input statement and print statement are given to you in the starting code. a sample run of the program is as follows: Enter a list of integers, separated by slashes: 7/3/6/8 resulting list:...

  • 1.     This project will extend Project 3 and move the encryption of a password to a...

    1.     This project will extend Project 3 and move the encryption of a password to a user designed class. The program will contain two files one called Encryption.java and the second called EncrytionTester.java. 2.     Generally for security reasons only the encrypted password is stored. This program will mimic that behavior as the clear text password will never be stored only the encrypted password. 3.     The Encryption class: (Additionally See UML Class Diagram) a.     Instance Variables                                                i.     Key – Integer...

  • In this lab, you will write a C program to encrypt a file. The program prompts...

    In this lab, you will write a C program to encrypt a file. The program prompts the user to enter a key (maximum of 5 bytes), then the program uses the key to encrypt the file. Note that the user might enter more than 5 characters, but only the first 5 are used. If a new line before the five characters, the key is padded with 'a'; Note that the new line is not a part of the key, but...

  • Write a short Java program that uses private key (symmetric) encryption method to encrypt a short...

    Write a short Java program that uses private key (symmetric) encryption method to encrypt a short string. Approximate algorithm: Enter a text string Use Java to generate a key and encrypt the string Use Java (and the key) to decrypt the string Compare original and decrypted string to make sure it is the same Note: Please make it as simple as possible

  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

  • I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text an...

    I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text and key My Current Code is: void SubDecrypt(char *message, char *encryptKey) { int iteration; int iteration_Num_Two = 0; int letter; printf("Enter Encryption Key: \n");                                                           //Display the message to enter encryption key scanf("%s", encryptKey);                                                                   //Input the Encryption key for (iteration = 0; message[iteration] != '0'; iteration++)                               //loop will continue till message reaches to end { letter = message[iteration];                                                      ...

  • Write a program that implements an elementary bit stream cipher. An elementary level bit stream cipher...

    Write a program that implements an elementary bit stream cipher. An elementary level bit stream cipher is an encryption algorithm that encrypts 1 byte of plain text at a time. This one uses a given 4-bit bit pattern as the key. The size of the encrypted message that we want to be able to send has a maximum length of 200 characters. You must: 1. prompt the user to input the clear text to be encrypted. You must use printf()...

  • Write a Python program which implements the following two classical cryptosystem which we covered n class:...

    Write a Python program which implements the following two classical cryptosystem which we covered n class: a) Affine Cipher b) Vigenere Cipher Your program should consist of at least five functions: a) Two functions named encrypt, one for each of the two algorithms which accepts a lowercase alphabetical plaintext string and key as input and outputs a corresponding cipher text string. b) Two functions named decrypt, one for each of the two algorithms which accepts a lowercase alphabetical ciphertext string...

  • C program (Not C++, or C#) Viginere Cipher 1)Ask the user if we are encrypting or...

    C program (Not C++, or C#) Viginere Cipher 1)Ask the user if we are encrypting or decrypting. 2) Ask the user to enter a sentence to be transformed. 3) Ask the user to enter a sentence that will be used as the encryption or decryption key. 4) The sentences (array of characters) should end with a NULL terminator '\0'. 5) The range of values will be all printable characters on the ASCII chart starting with a SPACE - Value 32,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT