Results 1 to 18 of 18

Thread: get the XOR value

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    256

    get the XOR value

    How can I get the XOR value any string
    Let say this is the String
    L7007F
    how can I get the XOR of this...
    any ideas....
    If an answer to your question has been helpful, then please, Rate it!

  2. #2
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Lightbulb Re: get the XOR value

    yes there are plenty of ideas. But to XOR something you have to have a value to XOR it with. example 5 XOR 1 = 4
    its a lot easier to xor numbers, but to do a string you would break it down into individual letters (using mid) and xor the char value with whatever you want.

    let's say Orwell$ contains your string you want to XOR
    let's say key& is your xor value
    Code:
    for cl =1 to len(orwell$)
    mid(orwell$, cl, 1) = chr(asc(orwell$, cl, 1) XOR key)
    next cl
    This code steps through the string in orwell$, converts each char to its ascii value, XORs it by key, converts it back and puts it back in.

    Hope this helps. To xor a string by another string simply convert both of them and xor them together (one char at a time) The 2nd string would be the decryptor for the first one (or vice versa )
    Last edited by Lord Orwell; Jun 2nd, 2007 at 04:33 AM. Reason: typed str instead of chr-oops! and didn't use closing code tag
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    256

    Re: get the XOR value

    Quote Originally Posted by Lord Orwell
    To xor a string by another string simply convert both of them and xor them together (one char at a time) The 2nd string would be the decryptor for the first one (or vice versa )
    Hi Lord...
    U mean to say suppose the String is "L7007F" then
    Step 1 - take L and 7 first XOR them
    Step 2- take the Result of Step 1 XOR it with the Next character in string i.e 0
    Step 3 - again take the result of Step 2 and XOR it with the next character i.e 0
    step 4 - again take the result of Step 3 and XOR it with the next character i.e 7
    step 5 - again take the result of Step 4 and XOR it with the next character i.e F

    The result that we get in the Step 5 is the XOR value of the String...
    This is the way it has to be done...right....
    If an answer to your question has been helpful, then please, Rate it!

  4. #4
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: get the XOR value

    no that isn't what i said at all. You can not xor a string by itself and still be able to know what the original was. What you just described is generating a checksum.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    256

    Re: get the XOR value

    What is a checksum ..?? and y is it used...
    If an answer to your question has been helpful, then please, Rate it!

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    256

    Re: get the XOR value

    Quote Originally Posted by Lord Orwell
    let's say Orwell$ contains your string you want to XOR
    let's say key& is your xor value
    can u please expalin me..
    what is a key and what would the Key be in the String Orwell$
    If an answer to your question has been helpful, then please, Rate it!

  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: get the XOR value

    Quote Originally Posted by Kuamr
    What is a checksum ..?? and y is it used...
    A checksum is just like it's called - it's a sum value that allows you to check that all the preceding digits made it in a transmission, for example, without data loss.

    Let's say you have the value 123

    The checksum would be 1+2+3, or 6.

    So the full transmitted value would be 1236.

    On the receiving end you take the 6 off - getting back to 123. You re-add those 3 digits - arriving at 6. Since the 6 matches the 6 - you know you have a good transmission.

    There are many methods for checksum generation. For example, if the values when added go larger than a single digit - something like 7+8+9 (which equals 24) would have a checksum value of 4 (taking only the right most digit).

    This method of checksum is used in transmitting ACH files to banks - so that the bank can verify that routing numbers and account numbers are accurate.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    256

    Re: get the XOR value

    than u very much for the Info szlamany...but as Lord Orwell said in Post#2 .what would be the Key if i 'm trying to get the XOR of the String L7007F
    If an answer to your question has been helpful, then please, Rate it!

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    256

    Re: get the XOR value

    I beleive that the Key is required only when u want to Xor with some value..
    What if i want to get the XORed value of the Entire String (L7007F)...any ideas........
    If an answer to your question has been helpful, then please, Rate it!

  10. #10
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: get the XOR value

    What do you mean by the XOR value??

    XOR is typically used to encrypt - see this link:

    http://en.wikipedia.org/wiki/Simple_XOR_cipher

    But if you want to XOR a string - each character one at a time - then you are creating a CHECKSUM - but not using addition (as I did in my example) but using XOR as the operator. You would simply loop through the string and take the ascii value of each character - XOR that with the prior value (and values) and keep going along. Not sure why you would want to do this though...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  11. #11
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: get the XOR value

    it depends on how much data loss you expect.
    if you want a checksum equal to a range of 0 to 255 then...
    Code:
    dim GeneratedChecksum as long
    Orwell$ = "String to get checksum for"
    for cl =1 to len(orwell$) 'a loop in this case 26 times
       char$ = mid(orwell$, cl, 1)
       generatedchecksum = generatedchecksum + asc(char$)
       if generatedchecksum > 255 then generatedchecksum = generatedchecksum - 256
    'above line keeps your value one byte long
    next cl
    msgbox "Checksum = " & generatedchecksum"
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  12. #12
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: get the XOR value

    Wouldn't you get the same checksum if you have the same string but the bytes are in a different order?

  13. #13
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: get the XOR value

    Digi, yeah...but that's not always an important bug when it comes to checksums...I mean, both MD5 and CRC32 have possibilities for doubles for much the same reason but there's *SO* many permutations that this rarely actually happens :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  14. #14
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: get the XOR value

    Quote Originally Posted by DigiRev
    Wouldn't you get the same checksum if you have the same string but the bytes are in a different order?
    So will the simple checksum of adding the digits that banks use for direct deposit transmissions...

    I believe that an old mainframe backup algorithm we used to have would XOR every two 512-byte records together and create a cyclic-redundancy record that got put onto the tape as well.

    I'm still not clear on whether the original poster wants an encryption algo or a checksum algo anyway...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  15. #15
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: get the XOR value

    Yeah. A basic checksum like that is also good enough for stuff like sending data over TCP/IP since TCP guarantees data will arrive in the same order.

    I think the OP was misinformed and thought you could just XOR a single value. I don't think he was aware you need another value to XOR it with.

    I would guess he was asking about a basic XOR encryption where you loop through the chars and XOR each letter with the letter from the key.

  16. #16
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: get the XOR value

    That type of XORing is exactly how raid 5 works as well. 2 drive sectors are xored together and the result is put on the 3rd. Oddly enough the 3rd drive is not just for xoring. For some reason they rotate.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    256

    Re: get the XOR value

    Thanks for the Info guys......I am not looking forward to encrypt anything using XOR...the primary reason for XOring the String is that I am actually developing a PMS interface which interacts with the PBX machine....
    The Scene is :
    The pms interface sends a message which would consists of a String ...
    the message format is as such
    Code:
    STX, sa,ua,message string,ETX,BCC
    STX - stands for start of text
    sa- system address
    ua - unit address
    message string - is the string whose XOR is to be calculated
    ETX - specifies the End of Text
    BCC- Block Check code (longitudinal redundancy checksum)

    Now the BCC contains the XORed value of the message String which it sends to the PBX.
    the PBX on the Other hand receives the message and again calculates the BCC form its side..(our program has to do nothing for this ..it is already done / come preloaded to calculate the BCC)

    If the BCC code from the sender (PMS) matches the BCC code calculated by the Receiver (PBX) then it means that the message is transfered sucesfully...
    If an answer to your question has been helpful, then please, Rate it!

  18. #18
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: get the XOR value

    Unless you have a specification for exactly what "longitudinal redundancy checksum" means, you'll have to try different algorithms on different blocks of data until you find the right one 9the one that produces the BCC that gets sent with that block).

    XORing each byte with the next is a form of lrc - so is CRC32. So is the check code used on hard drives, and it's different from the other two. There are probably at least a dozen lrc algorithms being used, and dozens more that used to be used.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width