Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming Exercise 4.7 Write A Script That Decrypts A Message Coded By The Met

ID: 3749416 • Letter: P

Question

Programming Exercise 4.7 Write A Script That Decrypts A Message Coded By The Method ... Question: Python Programming Exercise 4.7 Write a script that decrypts a message coded by the method used i... 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!

im getting the error "SyntaxError: 'return' outside function"

Programming Exercise 4.7 Instructions Write a script that decrypts a message coded by the method used in Project 6 Llil Method used in project 6: s/p 1. Add 1 to each character's 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: Enter the coded text: 0010011 1001101 1011011 1011011 1100001 000011 1110001 1100001 1100111 1011011 1001011 Hello world! Grading When you have completed your program, click the Submit button to record your score

Explanation / Answer

There was an indentation error in the function def shift() which is causing errors. Indentation plays a majo role in interpretation of python code and hence very trivial. Following is the corrected code.

def bits2string(b=''):
return chr(int(b, 2) - 1)


def shift(n=''):
temp = list(n)
new = (temp[-1:] + temp[0:-1])
ret = ""
for i in new:
ret = ret + i
return ret

coded = input("Enter the coded text: ")
process = coded.split(" ")
decoded = ""
for q in process:
decoded = decoded + bits2string(shift(q))

print
" Decoded Information: " + decoded