Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 761159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:48:17+00:00 2026-05-14T15:48:17+00:00

import sys import md5 from TOSSIM import * from RadioCountMsg import * t =

  • 0
import sys
import md5
from TOSSIM import *
from RadioCountMsg import *

t = Tossim([]) #The Tossim object is defined here 

m = t.mac()#The mac layer is defined here , in which the communication takes place
r = t.radio()#The radio communication link object is defined here , as the communication needs Rf frequency to transfer

t.addChannel("RadioCountToLedsC", sys.stdout)# The various channels through which communication will take place 
t.addChannel("LedsC", sys.stdout)

#The no of nodes that would be required in the simulation has to be entered here
print("enter the no of nodes you want ")
n=input()

for i in range(0, n):
  m = t.getNode(i)
  m.bootAtTime((31 + t.ticksPerSecond() / 10) * i + 1)
#The booting time is defined so that the time at which the node would  be booted is given

f = open("topo.txt", "r") #The topography is defined in topo.txt  so that the RF frequencies of the transmission between nodes are are set 
lines = f.readlines()
for line in lines:
  s = line.split()
  if (len(s) > 0):
    if (s[0] == "gain"):
      r.add(int(s[1]), int(s[2]), float(s[3])) #The topogrography is added to the radio object


noise = open("meyer-heavy.txt", "r") #The noise model is defined for the nodes 
lines = noise.readlines()
for line in lines:
  str = line.strip()
  if (str != ""):
    val = int(str)
    for i in range(0, 4):
      t.getNode(i).addNoiseTraceReading(val)

for i in range (0, n): 
  t.getNode(i).createNoiseModel() #The noise model is created for each node

for i in range(0,n):
  t.runNextEvent()
fk=open("key.txt","w")
for i in range(0,n):
    if i ==0 :
        key=raw_input()
        fk.write(key)
        ak=key
    key=md5.new()
    key.update(str(ak))
    ak=key.digest()
    fk.write(ak)
fk.close()
fk=open("key.txt","w")
plaint=open("pt.txt")
for i in range(0,n):
    msg = RadioCountMsg()
    msg.set_counter(7)
    pkt = t.newPacket()#A packet is defined according to a certain format 
    print("enter message to be transported") 
    ms=raw_input()#The message to be transported is taken as input
    #The RC5 encryption has to be done here 
    plaint.write(ms)
    pkt.setData(msg.data) 
    pkt.setType(msg.get_amType())
    pkt.setDestination(i+1)#The destination to which the packet will be sent is set 

    print "Delivering " + " to" ,i+1  
    pkt.deliver(i+1, t.time() + 3)


fk.close()

print "the key to be displayed"
ki=raw_input()
fk=open("key.txt")

for i in range(0,n):
    if i==ki:
        ms=fk.readline()



for i in range(0,n):
    msg=RadioCountMsg()
    msg.set_counter(7)
    pkt=t.newPacket()
    msg.data=ms
    pkt.setData(msg.data)
    pkt.setType(msg.get_amType())
    pkt.setDestination(i+1)
    pkt.deliver(i+1,t.time()+3)

#The key has to be broadcasted here so that the decryption can take place 

for i in range(0, n):
  t.runNextEvent();

this code gives me error here key.update(str(ak)) . when i run a similar code on the python terminal there is no such error but this code pops up an error . why so?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:48:18+00:00Added an answer on May 14, 2026 at 3:48 pm

    On line 35 you reassign ‘str’ from the built-in it originally references to a different object. Then, on line 53, you try to use it as the original built-in again. If you want to use ‘str’ as ‘str()’ on line 53, you need to use a different variable name up on line 35 (and 36, and 37)

    Don’t use ‘str’ here:

    for line in lines:
      str = line.strip()
      if (str != ""):
        for i in range(0, 4):
          t.getNode(i).addNoiseTraceReading(val)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 368k
  • Answers 368k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you never called socket.Bind, then on the first transmission… May 14, 2026 at 6:01 pm
  • Editorial Team
    Editorial Team added an answer you should select the id as well in the outer… May 14, 2026 at 6:01 pm
  • Editorial Team
    Editorial Team added an answer Unmanaged code is only abortable if it is an "alertable… May 14, 2026 at 6:01 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.