What does this function do?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anil Gupte

    #1

    What does this function do?

    I am trying to learn C++ and one sample written by someone for me contains
    this:

    void DecryptStream(B YTE* buf, ULONG size)
    {
    for (ULONG i=0; i<size; i++)
    {
    buf[i] ^= 1;
    }
    }

    Can some one tell me what this is doing? Especially ^ - is that an XOR?

    Thanx,
    --
    Anil Gupte
    Innovate with UsLeading the Way in Advanced Technology Solutions Discover state-of-the-art services in logistics, databases, and AI designed for evolving

    www.icinema.com


  • Cholo Lennon

    #2
    Re: What does this function do?

    "Anil Gupte" <anil-list@icinema.co mwrote in message
    news:ObtdotVQIH A.4880@TK2MSFTN GP03.phx.gbl...
    I am trying to learn C++ and one sample written by someone for me contains
    this:
    >
    void DecryptStream(B YTE* buf, ULONG size)
    {
    for (ULONG i=0; i<size; i++)
    {
    buf[i] ^= 1;
    }
    }
    >
    Can some one tell me what this is doing? Especially ^ - is that an XOR?
    >
    Yes, ^ is the C/C++ XOR operator, so the function 'decrypt' the stream of
    bytes (but can be used to 'crypt' the data too).

    Regards


    --
    Cholo Lennon
    Bs.As.
    ARG


    Comment

    • Ben Voigt [C++ MVP]

      #3
      Re: What does this function do?


      "Anil Gupte" <anil-list@icinema.co mwrote in message
      news:ObtdotVQIH A.4880@TK2MSFTN GP03.phx.gbl...
      >I am trying to learn C++ and one sample written by someone for me contains
      >this:
      >
      void DecryptStream(B YTE* buf, ULONG size)
      {
      for (ULONG i=0; i<size; i++)
      {
      buf[i] ^= 1;
      }
      }
      >
      Can some one tell me what this is doing? Especially ^ - is that an XOR?
      As Cholo already told you, yes that's XOR.

      It flips the least significant bit of each of <sizebytes starting at
      <buf>, which should not be called "decryption ".
      >
      Thanx,
      --
      Anil Gupte
      Innovate with UsLeading the Way in Advanced Technology Solutions Discover state-of-the-art services in logistics, databases, and AI designed for evolving

      www.icinema.com
      >

      Comment

      • Anil Gupte

        #4
        Re: What does this function do?

        Thanx for the info! Ben and Cholo.

        --
        Anil Gupte
        Innovate with UsLeading the Way in Advanced Technology Solutions Discover state-of-the-art services in logistics, databases, and AI designed for evolving

        www.icinema.com

        "Ben Voigt [C++ MVP]" <rbv@nospam.nos pamwrote in message
        news:OiiemBcQIH A.5692@TK2MSFTN GP04.phx.gbl...
        >
        "Anil Gupte" <anil-list@icinema.co mwrote in message
        news:ObtdotVQIH A.4880@TK2MSFTN GP03.phx.gbl...
        >>I am trying to learn C++ and one sample written by someone for me contains
        >>this:
        >>
        >void DecryptStream(B YTE* buf, ULONG size)
        >{
        > for (ULONG i=0; i<size; i++)
        > {
        > buf[i] ^= 1;
        > }
        >}
        >>
        >Can some one tell me what this is doing? Especially ^ - is that an XOR?
        >
        As Cholo already told you, yes that's XOR.
        >
        It flips the least significant bit of each of <sizebytes starting at
        <buf>, which should not be called "decryption ".
        >
        >>
        >Thanx,
        >--
        >Anil Gupte
        >www.keeninc.net
        >www.icinema.com
        >>
        >
        >

        Comment

        Working...