Question

In: Computer Science

Encryption is a technique used to keep information private. It involves transforming text into a new...

Encryption is a technique used to keep information private. It involves transforming text into a new unreadable sequence of characters by changing the text in some way using a key. The goal is to do this in such a way that someone else who has the key can decrypt the information. In this question, you will write a program to encrypt an input string with the help of a key and an alphabet string.

The program will start by setting up the alphabet string in your code as the following:

alphabet = "abcdefghijklmnopqrstuvwxyz0123456789.,!# " Note the white space at the end of the alphabet string.

You can copy and paste the above statement at the start of your program.

Your program will first prompt the user to enter some text, a phrase, to be encrypted. Your program will then prompt for an integer number, i.e., a numerical code, between 2 and 10 (including 2 and 10). You can assume the program’s user will enter the correct input (i.e., an integer between and including 2 and 10). The program will use this numerical code to compute the key.

To compute the key, your program should first sum up the ordinal values of all the characters in the input phrase that you want encrypted. The program should then compute the remainder of the division of the ordinal sum by the numerical code, and add one to the result, such as: key = sum % code + 1

Your program will then transform the input text into an encrypted sequence of characters using the above alphabet string and the key. To transform the input into an encrypted phrase, your program should go over each character in the input text and locate the character in the alphabet string. Your program will then use the index of the input character from the alphabet string to determine what the encryption will be for this character. The encryption will be the character found in the alphabet string at an index that precedes the index of the input character the alphabet string by key places. For example, if the input character is the letter a and the computed key is 2 then the encryption will be the # character. If the input character is 2 and the computed key is 6 then the encryption will be w.

3

Note, the computed key and the numerical input code are different. The numerical input code is used in computing the key. To obtain the key 2 when the input text is a the numerical input code has to be 2. To obtain the key 6 when the input text is 2 the input code has to be 9.

The program is phyton

Solutions

Expert Solution

PYTHON CODE:

# Encrypt function
def encrypt(text,s):
    # alphabet string
    alphabet = "abcdefghijklmnopqrstuvwxyz0123456789.,!# ";
    
    # Sum of all the ordinal values of all the characters in the input phrase are computed
    # and stored in the sum_values variable
    sum_values = 0;
    for char in text.lower():
        sum_values += ord(char);
    
    # Encrypted text is stored in the result variable
    result = "";
    
    # The key value is computed by finding the remainder of the division of the ordinal sum 
    # by the numerical code, and by adding one to the result, such as: key = sum % code + 1
    key = sum_values % code + 1;

    # index values are found and the output is stored in the result variable
    index = 0;
    for char in text.lower():
        index = (alphabet.index(char) - key);
        result += alphabet[index];
    return result;

# User will be asked to enter a phrase or a text and the value will be stored in the text variable
text = input("Enter a phrase / text  to encrypt: ");
# User will be asked to enter a numerical code between 2 and 10 and the value will be stored 
# in the code variable
code = int(input("Enter a numerical key value between 2 and 10: "));

# Input and Output values are displayed
print("Plain Phrase / Text : " + text);
print("Numerical Code : " + str(code));
print("Encrypted text: " + encrypt(text,code));

OUTPUT:


Related Solutions

One technique that can be used to roll back management transactions involves reverting to an earlier...
One technique that can be used to roll back management transactions involves reverting to an earlier configuration file. Discuss two scenarios to prove this as a true management transaction. Discuss also two scenarios to reveal drawbacks of this technique subject to true management transactions A customer is having problems connecting to a wireless network in a shared office space. The customer can detect several other wireless network signals. All of the wireless networks have different SSIDs but several are using...
Consider the following set of requirements for a university information system that is used to keep...
Consider the following set of requirements for a university information system that is used to keep track of students’ transcripts. R1: The university keeps track of each student's name, student number, class, and degree program. R2. The university consists of various departments. Each department is described by a name, department code and phone. R3. Each course has a course number, course name, and credits. R4. Each section has an instructor, course number, and section number. There might be multiple sections...
Computational Intelligence or Soft Computing, is a new advanced information processing technique that uses characteristics closely...
Computational Intelligence or Soft Computing, is a new advanced information processing technique that uses characteristics closely associated with human intelligence. Some common algorithms are Genetic Algorithms, Neural networks etc. Make a report on some of these algorithms and explain their advantages and usage areas. (2 paragraphs each algorithm at least)
Company “Text No Drive” is compiling background information for their new device that senses when texting...
Company “Text No Drive” is compiling background information for their new device that senses when texting is going on by the driver and stops the text. The company is interested in using injury statistics for their campaign. They compile information on the cost to the driver (in terms on injury and insurance costs) and also preferences by the driver. The cost to the driver is described as average cost per injury depending on the amount of texting that the driver...
There are four approaches/methods used to replace an old information system with the new one. Describe...
There are four approaches/methods used to replace an old information system with the new one. Describe the four approaches and identify the situations where each approach may be most appropriate/desirable to use.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT