<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>once I made an additional small mod to the key decoding </div><div><br></div><div>i.e.</div><div><div>encode(Key, Plaintext) -></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>K = list_to_tuple(int32list_from_binary(Key)),</div></div><div><br></div><div>I got success:</div><div><br></div><div>73> ice_crypto_btea:test().</div><div>{test,true,true,{<<"ab043705808c5d57">>,<<"ab043705808c5d57">>}}</div><div>{test,true,true,{<<"d1e78be2c746728a">>,<<"d1e78be2c746728a">>}}</div><div>{test,true,true,{<<"67ed0ea8e8973fc5">>,<<"67ed0ea8e8973fc5">>}}</div><div>{test,true,true,{<<"8c3707c01c7fccc4">>,<<"8c3707c01c7fccc4">>}}</div><div>{test,true,true,</div><div> {<<"b2601cefb078b772abccba6a">>,<<"b2601cefb078b772abccba6a">>}}</div><div>{test,true,true,</div><div> {<<"579016d143ed6247ac6710dd">>,<<"579016d143ed6247ac6710dd">>}}</div><div>{test,true,true,</div><div> {<<"c0a19f06ebb0d63925aa27f74cc6b2d0">>,</div><div> <<"c0a19f06ebb0d63925aa27f74cc6b2d0">>}}</div><div>{test,true,true,</div><div> {<<"01b815fd2e4894d13555da434c9d868a">>,</div><div> <<"01b815fd2e4894d13555da434c9d868a">>}}</div><div><br></div><div>My thanks to you for saving my sanity!</div><div><br></div><div>Best regards,</div><div>/s</div><div><br></div><div><div>On Nov 17, 2012, at 11:28 AM, Dmitry Kolesnikov <<a href="mailto:dmkolesnikov@gmail.com">dmkolesnikov@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hello,</div><div><br></div><div>This looks as endianness problem. You have to keep in-mind that binaries is big-endian by default, which contrasts with C memory. You have to be very careful of C algorithms mapping.</div><div><br></div><div>I've made a small fixes to int32list_xxx routines (see bold text):</div><div><br></div><div><div>int32list_from_binary(Bin) -></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>int32list_from_binary(Bin, []).</div><div>int32list_from_binary(<<X:32/<b>little</b>, Bin/binary>>, Acc) -></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>int32list_from_binary(Bin, [X|Acc]);</div><div>int32list_from_binary(<<>>, Acc) -></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>lists:reverse(Acc).</div><div><br></div><div>int32list_to_binary(List) -><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>list_to_binary([<<X:32/<b>little</b>>> || X <- List]).</div></div><div><br></div><div>Some of tests got passed. Unfortunately, some of tests are failed I hope you can easily validate rest of you code agains endian. </div><div><br></div><div><div>{test,true,true,{<<"ab043705808c5d57">>,<<"ab043705808c5d57">>}}</div><div>{test,false,true,{<<"26e3868b9d66a048">>,<<"d1e78be2c746728a">>}}</div><div>{test,false,true,{<<"2a70e36b99941f2d">>,<<"67ed0ea8e8973fc5">>}}</div><div>{test,false,true,{<<"a30d3870c0873c23">>,<<"8c3707c01c7fccc4">>}}</div><div>{test,true,true,</div><div> {<<"b2601cefb078b772abccba6a">>,<<"b2601cefb078b772abccba6a">>}}</div><div>{test,false,true,</div><div> {<<"ddbcb4b88b2c5a268081a8b4">>,<<"579016d143ed6247ac6710dd">>}}</div><div>{test,true,true,</div><div> {<<"c0a19f06ebb0d63925aa27f74cc6b2d0">>,</div><div> <<"c0a19f06ebb0d63925aa27f74cc6b2d0">>}}</div><div>{test,false,true,</div><div> {<<"bd28749d4fc20b73a79d59a25d55ab27">>,</div><div> <<"01b815fd2e4894d13555da434c9d868a">>}}</div></div><div><br></div><div>Best Regards,</div><div>Dmitry</div><div><br></div><br><div><div>On Nov 17, 2012, at 7:02 PM, Steve Davis wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">I am intrigued by what is arguably a pointless problem. <br><br>Looking at the tiny encryption algorithm aka XXTEA it seemed easy enough to implement in Erlang. I have an implementation (attached with source and all references inside the module) which encodes and decodes successfully... BUT the cipher text doesn't match the test vectors...<br><br>What makes this pointless is that I should "just make it a NIF" etc. But it's likely that I am misunderstanding some aspect of either Erlang or C, however I am confounded as to what that problem is... why does the attached implementation not generate the same ciphertext as in the test vectors from the C implementation? Can anyone spot my error?<br><br>Thanks,<br>/s<br><br><span><xxtea.erl.txt></span>_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br><a href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a><br></blockquote></div><br></div></blockquote></div><br></body></html>