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....
Printable View
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....
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
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.Code:for cl =1 to len(orwell$)
mid(orwell$, cl, 1) = chr(asc(orwell$, cl, 1) XOR key)
next cl
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 :))
Hi Lord...Quote:
Originally Posted by Lord Orwell
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....
:)
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.
What is a checksum ..?? and y is it used...
can u please expalin me..Quote:
Originally Posted by Lord Orwell
what is a key and what would the Key be in the String Orwell$
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.Quote:
Originally Posted by Kuamr
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.
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
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........
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...
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"
Wouldn't you get the same checksum if you have the same string but the bytes are in a different order?
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 :-)
So will the simple checksum of adding the digits that banks use for direct deposit transmissions...Quote:
Originally Posted by DigiRev
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...
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.
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.
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
STX - stands for start of textCode:STX, sa,ua,message string,ETX,BCC
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...
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.