Ask Your Question

Xor the output from SDES

asked 2013-05-07 19:06:33 -0600

Aye gravatar image

Hi again,

From the Stalling's cryptography textbook I use the xor function a following :

def XorBlock(block1, block2):

   Xors two blocks together.
   l = len(block1);
   if (l != len(block2)):
      raise ValueError, "XorBlock arguments must be same length"
   return [(block1[j]+block2[j]) % 2 for j in xrange(l)];

it works well when I use it to xor 2 blocks. But when I wanna xor the output from sDES function as following:

from sage.crypto.block_cipher.sdes import SimplifiedDES
sdes = SimplifiedDES()
T = [0,1,0,1,0,1,0,1]
K = [1, 0, 1, 0, 0, 0, 0, 0, 1, 0]

it will replies TypeError: unsupported operand parent(s) for '+': 'Free binary string monoid' and 'Integer Ring'

So, how could I store the sdes.encrypt(T,K) into a pure list so that the XorBlock could work???

Thank you !!!!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-05-07 20:31:01 -0600

ppurka gravatar image

The output of the sdes.encrypt function is a bit strange. The elements of the output can be coerced to the reals but not to integers. So, something like this should work. Replace your return with

return [(ZZ(RR(a)) + ZZ(RR(b))) % 2 for a,b in zip(block1, block2)]
edit flag offensive delete link more


its amazing!! may I ask where I could find related information of ZZ RR and zip??

Aye gravatar imageAye ( 2013-05-08 05:46:35 -0600 )edit

zip is just a [python command]( ZZ and RR are Sage classes for integer and float. You can get help by executing `ZZ?` and `RR?`, respectively.

ppurka gravatar imageppurka ( 2013-05-08 15:30:03 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-05-07 19:06:33 -0600

Seen: 88 times

Last updated: May 07 '13