Question: def decrypt _ coded _ text ( coded _ text ) : bit _ strings = coded _ text.split ( ) decrypted _ message =

def decrypt_coded_text(coded_text):
bit_strings = coded_text.split()
decrypted_message =""
for bit_string in bit_strings:
shifted_bits = bit_string[-1]+ bit_string[:-1]
try:
decrypted_ascii = int(shifted_bits, 2)-1
decrypted_message += chr(decrypted_ascii)
except ValueError:
print(f"Invalid bit string: {bit_string}")
continue
return decrypted_message
# Read from the file instead of the direct input
file_name = input("Enter the file name containing the coded text: ")
try:
with open(file_name, 'r') as file:
coded_text_input = file.read()
decrypted_output = decrypt_coded_text(coded_text_input)
print("Decrypted Message:", decrypted_output)
except FileNotFoundError:
print(f"File '{file_name}' not found.")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!