0

I am trying to encrypt data and send it over a TCP socket to my server. However I am getting the error, ValueError: Key must be 128 bit long for the code below:

from xtea import *
from socket import *
import datetime
import time
import sys
clientsocket = socket(AF_INET,SOCK_STREAM)
clientsocket.connect(("xx.xx.xx.xx",1234))
key2="0wYwcOnn"
text = "$123456781|tx|id1^1.1^2015-09-29 16:38:44^2015-09-29 19:48:44"
x = new(key2, mode=MODE_ECB)
c = x.encrypt(text)
clientsocket.send(c)
recv = clientsocket.recv(1024)
print(recv)

Can anyone please comment on this?

bobdxcool
  • 91
  • 1
  • 1
  • 10

2 Answers2

1

Increase the key size to 16-bytes.

XTEA is a 64-bit block Feistel cipher with a 128-bit key. Since "0wYwcOnn" is 64 bits (at best) what is the misunderstanding?

zaph
  • 111,848
  • 21
  • 189
  • 228
  • i wrote an XTEA library for PHP, i have a function called `XTEA::binary_key_to_int_array(string $key, int $padding_scheme = XTEA::PAD_0x00)` - guess what `$padding_scheme = XTEA::PAD_0x00` does :p – hanshenrik Mar 04 '19 at 13:32
0

XTEA requires a 128bit (16 bytes) key.

one possible padding scheme for keys that are less than 16 bytes long, is to simply pad it with null bytes until it's 16 bytes. according to the guy Wooble at irc://irc.freenode.net/#python , this should work:

key2=struct.pack('16s', b"0wYwcOnn")
  • it just fills the missing bytes with nulls until it's 16 bytes, or so i've been told. (idk, i don't do python programming)
hanshenrik
  • 19,904
  • 4
  • 43
  • 89