For some reason I am getting an error when I try to run the Sage implementation of SDES. I did not make any changes to the source code. I did add this to encrypt a plaintext.
Y = SDESEncrypt("10111101", "1010000010")
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)];
TypeError: not all arguments converted during string formatting
That error message is a sign that something is getting strings when it's not expecting to. SDESEncrypt starts
def SDESEncrypt(plaintext_block, K): r""" Performs a single SDES plaintext block encryption. (Given plaintext and key as bit lists.) """
You're not passing bit lists, you're passing strings. While I don't know anything about these functions or how they're supposed to work, it's pretty easy to turn your strings into bit lists and get a result:
sage: Integer("10111101",2).bits() [1, 0, 1, 1, 1, 1, 0, 1] sage: SDESEncrypt(Integer("10111101",2).bits(),Integer("1010000010",2).bits()) [0, 0, 1, 0, 1, 1, 1, 0]
assuming I copied the code correctly. Which I might not have done, so don't trust the result, but I'm pretty sure this that you're meant to pass a list of 0s and 1s, not a string.