Ask Your Question
0

Xor the output from SDES

asked 2013-05-08 02:06:33 +0100

Aye gravatar image

Hi again,

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

def XorBlock(block1, block2):

   r"""
   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]
sdes.encrypt(T,K)
XorBlock(sdes.encrypt(T,K),T)

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
1

answered 2013-05-08 03:31:01 +0100

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

Comments

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

Aye gravatar imageAye ( 2013-05-08 12:46:35 +0100 )edit

zip is just a [python command](http://docs.python.org/2/library/functions.html#zip). 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 22:30:03 +0100 )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

Stats

Asked: 2013-05-08 02:06:33 +0100

Seen: 2,149 times

Last updated: May 08 '13