0

can anyone tell me what i did wrong with the decryption part of this code? ive been looking at it for some time now (while working on other related stuff), and i cant seem to find the problem with it. its getting really retarded, on my part

**and this is not homework! i do not take any computer classes at all. im doing this because i want to, but im stuck, and cant find any answers**

```
# Tiny Encryption Algorithm
def add(value1, value2):
return (value1 +value2)%(2**32)
def makehex(value,size=8):
value = hex(value)[2:]
if value[-1] == 'L':
value = value[0:-1]
while len(value)<size:
value = '0' + value
return value
def TEA(data, key, mode, rounds = 64, delta = 0x9e3779b9, total = 0xc6ef3720):
data = [int(data[:8],16),int(data[8:],16)]
key = [int(key[:8],16),int(key[8:16],16),int(key[16:24],16),int(key[24:],16)]
cycles = rounds/2
if mode == 'e':
total = 0
for i in range(cycles):
total = (total+delta)%2**32
data[0] = add(add(data[1]<<4, key[0]) ^ add(data[1], total) ^ add(data[1]>>5, key[1]), data[0])
data[1] = add(add(data[0]<<4, key[2]) ^ add(data[0], total) ^ add(data[0]>>5, key[3]), data[1])
else:
for i in range(cycles):
data[1] = add(add(data[0]<<4, key[2]) ^ add(data[0], total) ^ add(data[0]>>5, key[3]), -data[1])
data[0] = add(add(data[1]<<4, key[0]) ^ add(data[1], total) ^ add(data[1]>>5, key[1]), -data[0])
total -= delta
return makehex(data[0])+makehex(data[1])
# Plain Text : 0123456789abcdef
# Cipher Key : 00112233445566778899aabbccddeeff
# Cipher Text : 126c6b92c0653a3e
key = '00112233445566778899aabbccddeeff'
ctext =TEA('0123456789abcdef',key,'e')
print ctext,ctext == '126c6b92c0653a3e' # gives me true
ctext = TEA(ctext,key,'d')
print ctext, ctext == '0123456789abcdef' # gives me false: 66dfc50da4915142
```

isnt this basically what is shown on wikipedia, but in python? so why isnt it working?