Question

python Programming Exercise 4.7

Write a script that decrypts a message coded by the method used in Project 6.

Method used in project 6:

Add 1 to each character’s numeric ASCII value.

Convert it to a bit string.

Shift the bits of this string one place to the left.

A single-space character in the encrypted string separates the resulting bit strings.

An example of the program input and output is shown below:

Enter the coded text: 0010011 1001101 1011011 1011011 1100001 000011 1110001 1100001 1100111 1011011 1001011 000101

Hello world! 

Programming Exercise 4.7 Instructions Write a script that decrypts a message coded by the method used in Project 6 Method used in project 6 1. Add 1 to each characters numeric ASCII value 2. Convert it to a bit string. 3. Shift the bits of this string one place to the left. A single-space character in the encrypted string separates the resulting bit strings An example of the program input and output is shown below: Hello world!

1 0
Add a comment Improve this question Transcribed image text
Answer #1

Provided code is done as per your requirements.

  • "Screen shot program code" for better understanding.
  • "Code to copy" for run the program in your IDE.

Code Image:

#Implementation of bits2String method def bits2string (b): return chr (int (b, 2)-1) #Implementation of shift method def shift (n- templist (n) ret = for i in new: ret i return ret #Get the input from user coded input (Enter the coded text:) #split the code process-coded.split () decoded for q in process: decoded - bits2String (Shift (g)) #Display the decoded message print (decoded)

Sample Output:

Code to Copy:

#Implementation of bits2String method

def bits2String(b=''):

    return chr(int(b,2) - 1)

#Implementation of shift method

def shift(n=''):

    temp = list(n)

    new = (temp[-1:] + temp[0:-1])

    ret = ''

    for i in new:

        ret += i

    return ret

#Get the input from user

coded = input('Enter the coded text:')

#split the code

process = coded.split()

decoded = ''

for q in process:

    decoded += bits2String(shift(q))

#Display the decoded message

print(decoded)

Add a comment
Know the answer?
Add Answer to:
python Programming Exercise 4.7 Write a script that decrypts a message coded by the method used...
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
  • Programming Exercise 4.6 Use the strategy of the decimal to binary conversion and the bit shift...

    Programming Exercise 4.6 Use the strategy of the decimal to binary conversion and the bit shift left operation defined in Project 5 bits = input("Enter bit string: ") bits = bits[1:] + bits[0] print ("Result:", bits) to code a new encryption algorithm. The algorithm should Add 1 to each character’s numeric ASCII value. Convert it to a bit string. Shift the bits of this string one place to the left. A single-space character in the encrypted string separates the resulting...

  • C++ Program, Decode a Secret Message.

    Your country is at war and your enemies are using a secret code to communicate with each other.You have managed to intercept a message that reads asfollows::mmZdxZmx]ZpgyThe message is obviously encrypted using the enemy's secret code.You have just learned that their encryption method is based upon the ASCII code.Appendix 3 of your book shows the ACII character set.Individual characters in a string are encoded using this system. For example, the letter "A" isencoded using the number 65 and "B" is...

  • C++ please Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require...

    C++ please Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require that you read in an encrypted message from a file, decode the message, and then output the message to a file. The encryption method being used on the file is called a shift cipher (Info Here). I will provide you with a sample encrypted message, the offset, and the decrypted message for testing. For this project I will provide you main.cpp, ShiftCipher.h, and ShiftCipher.cpp....

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
ADVERTISEMENT