0

I am trying to se if I can use XXTEA in my application.

The code that I found on Wikipedia code is only for encryption and there is no code for decryption.

How can I decrypt with XXTEA?

I am developing c++ in windows (visual studio 2012)

mans
  • 17,104
  • 45
  • 172
  • 321
  • 1
    The description on Wikipedia implies the same code will encode and decode. – benjymous Nov 18 '13 at 13:21
  • @benjymous but it doesn't! – mans Nov 18 '13 at 13:23
  • Maybe you can use it, but you almost certainly shouldn't. Rolling your own crypto is already a recipe for weaknesses, but using a well-known broken cipher means the attack is even easier. Even most embedded devices can afford AES, I can guarantee that you can afford using a stronger cipher. –  Nov 18 '13 at 13:23
  • 1
    Have you tried making n negative? That's what makes id decode instead of encode. Reading the code should tell you that, as there are comments in the example. – benjymous Nov 18 '13 at 13:26
  • @delnan: I am happy to use AES, but I can not find any simple code that I can drop to mu project and using it. Is there any such simple code around? – mans Nov 18 '13 at 13:35
  • What's a "mu" project? Serious crypto is sufficiently complicated that you should use an external library instead of copying code. Use an existing library, ideally one that's popular and audited. Then your biggest concern is that you use the AES primitive wrong, but that's a different issue and can be fixed later. Of course, I'm operating on the assumption that you actually want some degree of security, rather than just toying around. –  Nov 18 '13 at 14:55
  • @delnan sorry I meant My project! I am looking for a crypto library that I can add it to my repository as a visual studio project rather than compiling it and using t externally. – mans Nov 18 '13 at 16:48

1 Answers1

2

The code snippet in the article apparently uses negative values of n to mean decoding.

#include <stdio.h>
#include <stdint.h>

void btea(uint32_t *v, int n, uint32_t const key[4]); /* ... */

int main(void) {

  char s[128] = "hello world bla bla bla bla bla bla";
  uint32_t key[4] = {1,2,3,4};

  int n = 128 / sizeof(uint32_t);

  printf("%s\n",s);
  btea((uint32_t*)s, n, key);
  printf("%s\n",s);
  btea((uint32_t*)s, -n, key);
  printf("%s\n",s);
}

prints:

$ ./a.out | hexdump -C
00000000  68 65 6c 6c 6f 20 77 6f  72 6c 64 20 62 6c 61 20  |hello world bla |
00000010  62 6c 61 20 62 6c 61 20  62 6c 61 20 62 6c 61 20  |bla bla bla bla |
00000020  62 6c 61 0a 2f 44 86 75  d5 16 83 bd 5d 20 af f3  |bla./D.u....] ..|
00000030  a7 dd bf 9f 3a cd a0 13  ef 2b 89 48 2e f6 89 20  |....:....+.H... |
00000040  e2 ba e4 9f ed 38 d1 86  43 82 9e a6 47 6c e4 6d  |.....8..C...Gl.m|
00000050  a8 82 22 9e cb 5b d1 a1  18 14 ef 18 ca 23 26 cc  |.."..[.......#&.|
00000060  18 1d 4f ba 1b d5 f5 d0  45 72 1c 69 b9 22 a3 08  |..O.....Er.i."..|
00000070  44 71 1f 3b 8f a9 9d 5b  14 93 7b 59 b4 6b e8 1b  |Dq.;...[..{Y.k..|
00000080  18 97 1b 74 61 d6 e9 e9  60 96 8e 4c 26 be 21 fc  |...ta...`..L&.!.|
00000090  75 9f 4a 18 67 46 f0 95  2b ca 90 d9 f4 ce 3f 2f  |u.J.gF..+.....?/|
000000a0  44 82 56 44 c0 0a 39 57  ff 7f 0a 68 65 6c 6c 6f  |D.VD..9W...hello|
000000b0  20 77 6f 72 6c 64 20 62  6c 61 20 62 6c 61 20 62  | world bla bla b|
000000c0  6c 61 20 62 6c 61 20 62  6c 61 20 62 6c 61 0a     |la bla bla bla.|
000000cf
Vlad
  • 18,195
  • 4
  • 41
  • 71