Page 1 of 1

Decryption using XOR logic

Posted: Thu Jul 12, 2007 6:56 pm
by ramesh_dw
I have a requirement to decrypt a cipher text which was encrypted using an XOR function. I have to decrypt that string and load that value into an oracle table.

I could not find a relevant function call or BASIC statement using which I can write a routine. Any help is much appreciated.

I searched for XOR function in the forum and could not find any relevant post.

Thanks in advance
Ramesh

Posted: Thu Jul 12, 2007 7:10 pm
by ArndW
The DataStage BASIC programmer's Guide has a description of the BITXOR (V1,V2 ) function which you can use to revert your modified string back to the original one, given you know the string with which you XOR'd in the first place.

Posted: Thu Jul 12, 2007 8:37 pm
by ray.wurlod
Alternatively write your own.

Code: Select all

FUNCTION XOR(Arg1,Arg2)
Ans = (Arg1 Or Arg2) And (Not(Arg1 And Arg2))
RETURN(Ans)

Posted: Fri Jul 13, 2007 11:15 am
by ramesh_dw
Thanks for the response Arnd and Ray. I tired both the solutions and the values that I get are either 0 or 1.

For example

I tried encrypting and decrypting in DataStage itself

500 is the input value
55555 is the key used for encryption..

StgEncoded=(500 Or 55555) And (Not(500 And 55555)) (turns out to be 0)

DecodedvLaue= (StgEncoded Or 55555) And (Not(StgEncoded And 55555))
(turns out to be 1)

I am expecting to get 500 back as the output of Decodedvalue. Is it possible in DataStage?

Even BITXOR seem to evaluate expressions and return either true or false.
Am I missing something?

Thanks
Ramesh

Posted: Fri Jul 13, 2007 11:41 am
by ramesh_dw
BITXOR() worked for me. Thanks Arnd.

Posted: Fri Jul 13, 2007 3:05 pm
by ray.wurlod
Please mark the thread as Resolved.

For future searchers, please consult the manual before using BitXOR() function; it expects two decimal integer arguments. It performs XOR on each of the corresponding pairs of bits in these integers.

Depending on what you're doing you may need to convert binary, octal or hexadecimal data to decimal before using the BitXOR() function. XTD() can be used for hexadecimal, Iconv() can be used for all three.