Ok, something is wrong somewhere. (I am not an algorithm guy so I am less likely to figure it out).
But, This site here: http://www.bierkandt.org/encryption/symmetric_encryption.php
ecb mode, key 1234567812345678, Text is “Hello Wo” (just to fill 8 bytes)
Gives me a result of: XTEA: 3d3147376932abd0
This result matched identically under the same conditions when I ran it under Java, using the same subroutine I had used for the last few years.
In Xojo, This is my setup:
Dim datablock as New Memoryblock(8) '8 bytes, 2 UInt32 Blocks
Dim Keyblock as New MemoryBlock(16) '128 bit key, 4 Uin32 Blocks
Keyblock = "1234567812345678"
datablock = "Hello Wo"
arg = Encipher(32, Array(datablock.UInt32Value(0), datablock.UInt32Value(1)), Array(keyblock.uint32value(0), keyblock.uint32value(1), keyblock.uint32value(2), keyblock.uint32value(3)))
stdout.writeline(arg)
this does NOT match anything, I get this instead:
26A90517980A5390
Here is the code I used (slightly modified from above, only on return)
Public Function Encipher(numRounds As UInt32, v() As UInt32, key() As UInt32) as String
dim v0 as UInt32 = v( 0 )
dim v1 as UInt32 = v( 1 )
dim sum as UInt32
const delta as UInt32 = &h9E3779B9
dim lastRound as UInt32 = numRounds - 1
for i as UInt32 = 0 to lastRound
v0 = v0 + ( _
( Bitwise.ShiftLeft( v1, 4, 32 ) xor Bitwise.ShiftRight( v1, 5, 32 ) ) xor _
( sum + key( sum and 3 ) ) _
)
sum = sum + delta
v1 = v1 + ( _
( ( Bitwise.ShiftLeft( v0, 4, 32 ) xor Bitwise.ShiftRight( v0, 5, 32 ) ) + v0 ) xor _
( sum + key( Bitwise.ShiftRight( sum, 11, 32 ) and 3 ) ) _
)
next i
Return Hex32(v0) + Hex32(v1)
'v( 0 ) = v0
'v( 1 ) = v1
//#if false
//
// Original C code
//
//unsigned int i;
//uint32_t v0=v[0], v1=v[1], sum=0, delta=0x9E3779B9;
//for (i=0; i < num_rounds; i++) {
//v0 += (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]);
//sum += delta;
//v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + key[(sum>>11) & 3]);
//}
//v[0]=v0; v[1]=v1;
//}
//#endif
End Function
Then Hex32 (found elsewhere)
Public Function Hex32(value As Int32) as String
Const prefix = "00000000" // A 32-bits value is 8 digits long at max
Return Right(prefix + Hex(value), 8) // We always return 8 characters
End Function
Thoughts?