Intercepting and changing a message using python with the BBC:Microbit

I have a question where I have to intercept a message which is Alice:Bob:Go and Alice:Charlie:Go but I have to change the message to Alice:Bob:wait and Alice:Charlie:wait and then send it to the person who it was meant to go to.

Here is the exact question:

Alice is a hacker who is about to order her troops Bob and Charlie to attack. Unfortunately for Alice, her router used an easily cracked password and you, the ethical network engineer have gained access to the router. You now have the power to stop the attack because all of Alice's traffic will be going through the router.Bob and Charlie are waiting for the message, 'go' to arrive, which is the agreed signal between them for a coordinated attack. Alice will periodically send messages to Bob and Charlie, and needs to get an acknowledgement for each message. Your task is to intercept the router messages from 'Alice'. Check the payload of the messages from 'Alice'. If they contain 'go', change the payload to 'wait', and continue to send the message as normal. This way, Bob and Charlie will never get the attack signal. The routing table Alice uses is loaded into your code window: routing_table = {'Alice': 8, 'Bob': 10, 'Charlie': 15}

Everytime I submit the below code it comes up with this "Testing lots of different messages. Did you remember to look up the channel from the routing table?"

Here is my code:

from microbit import *
import radio

routing_table = { 'Alice': 8, 'Bob': 10, 'Charlie': 15 }

def forward_message(msg):
 new_channel = routing_table[destination]
 radio.config(channel=new_channel)
 radio.send(msg)

def send_back_ack(ack):
 new_channel = routing_table['Alice']
 radio.config(channel=new_channel)
 radio.send(ack)

radio.on()
radio.config(channel=routing_table['Alice'])

while True:
 msg = radio.receive()
 if msg:
  source, destination, payload = msg.split(':')
  if source == 'Alice' and payload =='go' and destination == 'Bob':
   msg = 'Alice:Bob:wait' 
  if destination == 'Charlie':
   msg = 'Alice:Charlie:wait'
  forward_message(msg)

  ack = radio.receive()
  while ack is None:
   ack = radio.receive()
  send_back_ack(ack)


Read more here: https://stackoverflow.com/questions/65717548/intercepting-and-changing-a-message-using-python-with-the-bbcmicrobit

Content Attribution

This content was originally published by Muhammad MOAZ at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: