Cyclic Redundancy Check comparison has different values Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live! The [wrap] tag is in the process of being burninatedHow do I check if a list is empty?How do I check whether a file exists without exceptions?What is the difference between @staticmethod and @classmethod?Difference between append vs. extend list methods in PythonHow do I check if a string is a number (float)?How do I sort a dictionary by value?Difference between __str__ and __repr__?Check if a given key already exists in a dictionaryWhy can't Python parse this JSON data?How to access environment variable values?

また usage in a dictionary

Fundamental Solution of the Pell Equation

Is there a holomorphic function on open unit disc with this property?

Would "destroying" Wurmcoil Engine prevent its tokens from being created?

Why do the resolve message appear first?

Delete nth line from bottom

Quick way to create a symlink?

Can a party unilaterally change candidates in preparation for a General election?

What is homebrew?

How to show element name in portuguese using elements package?

Why wasn't DOSKEY integrated with COMMAND.COM?

Declining "dulcis" in context

If my PI received research grants from a company to be able to pay my postdoc salary, did I have a potential conflict interest too?

What does this Jacques Hadamard quote mean?

Is the Standard Deduction better than Itemized when both are the same amount?

How do I stop a creek from eroding my steep embankment?

What does "lightly crushed" mean for cardamon pods?

Around usage results

What does the "x" in "x86" represent?

When a candle burns, why does the top of wick glow if bottom of flame is hottest?

Why aren't air breathing engines used as small first stages

Wu formula for manifolds with boundary

Why do we bend a book to keep it straight?

Is there such thing as an Availability Group failover trigger?



Cyclic Redundancy Check comparison has different values



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!
The [wrap] tag is in the process of being burninatedHow do I check if a list is empty?How do I check whether a file exists without exceptions?What is the difference between @staticmethod and @classmethod?Difference between append vs. extend list methods in PythonHow do I check if a string is a number (float)?How do I sort a dictionary by value?Difference between __str__ and __repr__?Check if a given key already exists in a dictionaryWhy can't Python parse this JSON data?How to access environment variable values?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















There are 3 codes that need to do the following actions:



  • A sends a message to B along with the CRC32 code.

  • B receives this message and CRC32 code.

  • B follows a 40% probability to change the message.

  • B sends the message along with the original CRC32 code to C.

  • C receives the message and CRC32 code and check whether it is correct or not.

For some reason, in part C when I compare the CRC's they are never equal, what am I missing?



Part A:



import socket
import struct
import sys
import binascii

def crc32(v):
r = binascii.crc32(v.encode())
return r


if len(sys.argv) != 3:
print("Useage: python " + sys.argv[0] + " <ip> <liseten port>")
sys.exit(-1)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
while True:
print("Input text:")
text = sys.stdin.readline().strip()
ss = struct.pack("!50sL",text.encode(),crc32(text))
s.sendto(ss,(sys.argv[1],int(sys.argv[2])))
if text == "bye":
break


Part B:



import socket
import operator
import sys
import binascii
import struct
import random

def crc32(v):
return binascii.crc32(v.encode())

if len(sys.argv) != 3:
print("Useage: python " + sys.argv[0] + " <liseten port>")
sys.exit(-1)

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(("0.0.0.0", int(sys.argv[1])))
print("Waiting...")
while True:
data, addr = s.recvfrom(1024)
str,crc = struct.unpack("!50sL",data)
str = str.decode("utf-8").replace("","")
if random.randint(0,100) < 40:
str = str + "x"
print("str:%sncrc:%X" % (str,crc & 0xffffffff))
str2 = str.encode("utf-8")
tpack = struct.pack("!50sL", str2, crc)
s.sendto(tpack,("127.0.0.1",int(sys.argv[2])))

if str == "bye":
break


Part C:



import socket
import operator
import sys
import binascii
import struct

def crc32(v):
return binascii.crc32(v.encode())

if len(sys.argv) != 2:
print("Useage: python " + sys.argv[0] + " <liseten port>")
sys.exit(-1)

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(("0.0.0.0", int(sys.argv[1])))
print("Waiting...")
while True:
data, addr = s.recvfrom(1024)
str,crc = struct.unpack("!50sL",data)
str = str.decode("utf-8")
print("str:%sncrc:%X" % (str,crc & 0xffffffff))

ncrc = crc32(str)
if ncrc == crc:
print("both messages are the same")
if str == "bye":
break









share|improve this question




























    0















    There are 3 codes that need to do the following actions:



    • A sends a message to B along with the CRC32 code.

    • B receives this message and CRC32 code.

    • B follows a 40% probability to change the message.

    • B sends the message along with the original CRC32 code to C.

    • C receives the message and CRC32 code and check whether it is correct or not.

    For some reason, in part C when I compare the CRC's they are never equal, what am I missing?



    Part A:



    import socket
    import struct
    import sys
    import binascii

    def crc32(v):
    r = binascii.crc32(v.encode())
    return r


    if len(sys.argv) != 3:
    print("Useage: python " + sys.argv[0] + " <ip> <liseten port>")
    sys.exit(-1)
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    while True:
    print("Input text:")
    text = sys.stdin.readline().strip()
    ss = struct.pack("!50sL",text.encode(),crc32(text))
    s.sendto(ss,(sys.argv[1],int(sys.argv[2])))
    if text == "bye":
    break


    Part B:



    import socket
    import operator
    import sys
    import binascii
    import struct
    import random

    def crc32(v):
    return binascii.crc32(v.encode())

    if len(sys.argv) != 3:
    print("Useage: python " + sys.argv[0] + " <liseten port>")
    sys.exit(-1)

    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind(("0.0.0.0", int(sys.argv[1])))
    print("Waiting...")
    while True:
    data, addr = s.recvfrom(1024)
    str,crc = struct.unpack("!50sL",data)
    str = str.decode("utf-8").replace("","")
    if random.randint(0,100) < 40:
    str = str + "x"
    print("str:%sncrc:%X" % (str,crc & 0xffffffff))
    str2 = str.encode("utf-8")
    tpack = struct.pack("!50sL", str2, crc)
    s.sendto(tpack,("127.0.0.1",int(sys.argv[2])))

    if str == "bye":
    break


    Part C:



    import socket
    import operator
    import sys
    import binascii
    import struct

    def crc32(v):
    return binascii.crc32(v.encode())

    if len(sys.argv) != 2:
    print("Useage: python " + sys.argv[0] + " <liseten port>")
    sys.exit(-1)

    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind(("0.0.0.0", int(sys.argv[1])))
    print("Waiting...")
    while True:
    data, addr = s.recvfrom(1024)
    str,crc = struct.unpack("!50sL",data)
    str = str.decode("utf-8")
    print("str:%sncrc:%X" % (str,crc & 0xffffffff))

    ncrc = crc32(str)
    if ncrc == crc:
    print("both messages are the same")
    if str == "bye":
    break









    share|improve this question
























      0












      0








      0








      There are 3 codes that need to do the following actions:



      • A sends a message to B along with the CRC32 code.

      • B receives this message and CRC32 code.

      • B follows a 40% probability to change the message.

      • B sends the message along with the original CRC32 code to C.

      • C receives the message and CRC32 code and check whether it is correct or not.

      For some reason, in part C when I compare the CRC's they are never equal, what am I missing?



      Part A:



      import socket
      import struct
      import sys
      import binascii

      def crc32(v):
      r = binascii.crc32(v.encode())
      return r


      if len(sys.argv) != 3:
      print("Useage: python " + sys.argv[0] + " <ip> <liseten port>")
      sys.exit(-1)
      s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      while True:
      print("Input text:")
      text = sys.stdin.readline().strip()
      ss = struct.pack("!50sL",text.encode(),crc32(text))
      s.sendto(ss,(sys.argv[1],int(sys.argv[2])))
      if text == "bye":
      break


      Part B:



      import socket
      import operator
      import sys
      import binascii
      import struct
      import random

      def crc32(v):
      return binascii.crc32(v.encode())

      if len(sys.argv) != 3:
      print("Useage: python " + sys.argv[0] + " <liseten port>")
      sys.exit(-1)

      s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      s.bind(("0.0.0.0", int(sys.argv[1])))
      print("Waiting...")
      while True:
      data, addr = s.recvfrom(1024)
      str,crc = struct.unpack("!50sL",data)
      str = str.decode("utf-8").replace("","")
      if random.randint(0,100) < 40:
      str = str + "x"
      print("str:%sncrc:%X" % (str,crc & 0xffffffff))
      str2 = str.encode("utf-8")
      tpack = struct.pack("!50sL", str2, crc)
      s.sendto(tpack,("127.0.0.1",int(sys.argv[2])))

      if str == "bye":
      break


      Part C:



      import socket
      import operator
      import sys
      import binascii
      import struct

      def crc32(v):
      return binascii.crc32(v.encode())

      if len(sys.argv) != 2:
      print("Useage: python " + sys.argv[0] + " <liseten port>")
      sys.exit(-1)

      s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      s.bind(("0.0.0.0", int(sys.argv[1])))
      print("Waiting...")
      while True:
      data, addr = s.recvfrom(1024)
      str,crc = struct.unpack("!50sL",data)
      str = str.decode("utf-8")
      print("str:%sncrc:%X" % (str,crc & 0xffffffff))

      ncrc = crc32(str)
      if ncrc == crc:
      print("both messages are the same")
      if str == "bye":
      break









      share|improve this question














      There are 3 codes that need to do the following actions:



      • A sends a message to B along with the CRC32 code.

      • B receives this message and CRC32 code.

      • B follows a 40% probability to change the message.

      • B sends the message along with the original CRC32 code to C.

      • C receives the message and CRC32 code and check whether it is correct or not.

      For some reason, in part C when I compare the CRC's they are never equal, what am I missing?



      Part A:



      import socket
      import struct
      import sys
      import binascii

      def crc32(v):
      r = binascii.crc32(v.encode())
      return r


      if len(sys.argv) != 3:
      print("Useage: python " + sys.argv[0] + " <ip> <liseten port>")
      sys.exit(-1)
      s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      while True:
      print("Input text:")
      text = sys.stdin.readline().strip()
      ss = struct.pack("!50sL",text.encode(),crc32(text))
      s.sendto(ss,(sys.argv[1],int(sys.argv[2])))
      if text == "bye":
      break


      Part B:



      import socket
      import operator
      import sys
      import binascii
      import struct
      import random

      def crc32(v):
      return binascii.crc32(v.encode())

      if len(sys.argv) != 3:
      print("Useage: python " + sys.argv[0] + " <liseten port>")
      sys.exit(-1)

      s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      s.bind(("0.0.0.0", int(sys.argv[1])))
      print("Waiting...")
      while True:
      data, addr = s.recvfrom(1024)
      str,crc = struct.unpack("!50sL",data)
      str = str.decode("utf-8").replace("","")
      if random.randint(0,100) < 40:
      str = str + "x"
      print("str:%sncrc:%X" % (str,crc & 0xffffffff))
      str2 = str.encode("utf-8")
      tpack = struct.pack("!50sL", str2, crc)
      s.sendto(tpack,("127.0.0.1",int(sys.argv[2])))

      if str == "bye":
      break


      Part C:



      import socket
      import operator
      import sys
      import binascii
      import struct

      def crc32(v):
      return binascii.crc32(v.encode())

      if len(sys.argv) != 2:
      print("Useage: python " + sys.argv[0] + " <liseten port>")
      sys.exit(-1)

      s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      s.bind(("0.0.0.0", int(sys.argv[1])))
      print("Waiting...")
      while True:
      data, addr = s.recvfrom(1024)
      str,crc = struct.unpack("!50sL",data)
      str = str.decode("utf-8")
      print("str:%sncrc:%X" % (str,crc & 0xffffffff))

      ncrc = crc32(str)
      if ncrc == crc:
      print("both messages are the same")
      if str == "bye":
      break






      python sockets udp crc crc32






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 18:51









      godspeeddgodspeedd

      31




      31






















          1 Answer
          1






          active

          oldest

          votes


















          1














          You forgot to replace the null bytes in Part C. You calculated the CRC in Part A before packing to 50 bytes, and removed them in Part B when displaying the received value.



          str = str.decode("utf-8")


          should b:



          str = str.decode("utf-8").replace('','')


          Note: str is a builtin function that you lose access to by using it as a variable name.






          share|improve this answer























          • Thank you so very much, that did indeed solve the issue.

            – godspeedd
            Mar 11 at 18:10











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069307%2fcyclic-redundancy-check-comparison-has-different-values%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You forgot to replace the null bytes in Part C. You calculated the CRC in Part A before packing to 50 bytes, and removed them in Part B when displaying the received value.



          str = str.decode("utf-8")


          should b:



          str = str.decode("utf-8").replace('','')


          Note: str is a builtin function that you lose access to by using it as a variable name.






          share|improve this answer























          • Thank you so very much, that did indeed solve the issue.

            – godspeedd
            Mar 11 at 18:10















          1














          You forgot to replace the null bytes in Part C. You calculated the CRC in Part A before packing to 50 bytes, and removed them in Part B when displaying the received value.



          str = str.decode("utf-8")


          should b:



          str = str.decode("utf-8").replace('','')


          Note: str is a builtin function that you lose access to by using it as a variable name.






          share|improve this answer























          • Thank you so very much, that did indeed solve the issue.

            – godspeedd
            Mar 11 at 18:10













          1












          1








          1







          You forgot to replace the null bytes in Part C. You calculated the CRC in Part A before packing to 50 bytes, and removed them in Part B when displaying the received value.



          str = str.decode("utf-8")


          should b:



          str = str.decode("utf-8").replace('','')


          Note: str is a builtin function that you lose access to by using it as a variable name.






          share|improve this answer













          You forgot to replace the null bytes in Part C. You calculated the CRC in Part A before packing to 50 bytes, and removed them in Part B when displaying the received value.



          str = str.decode("utf-8")


          should b:



          str = str.decode("utf-8").replace('','')


          Note: str is a builtin function that you lose access to by using it as a variable name.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 9 at 0:26









          Mark TolonenMark Tolonen

          97.1k13116177




          97.1k13116177












          • Thank you so very much, that did indeed solve the issue.

            – godspeedd
            Mar 11 at 18:10

















          • Thank you so very much, that did indeed solve the issue.

            – godspeedd
            Mar 11 at 18:10
















          Thank you so very much, that did indeed solve the issue.

          – godspeedd
          Mar 11 at 18:10





          Thank you so very much, that did indeed solve the issue.

          – godspeedd
          Mar 11 at 18:10



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069307%2fcyclic-redundancy-check-comparison-has-different-values%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

          Алба-Юлія

          Захаров Федір Захарович