Ahmed Laatabi
Ahmed Laatabi

Reputation: 927

SMS encryption/decryption in J2ME

I want to encrypt and decrypt SMS with J2ME, i tried TEA algorithm, but it generates a long encrypted text. Is there any other lightweight algorithm that generates an encrypted text with the same length as original text?

Upvotes: 0

Views: 616

Answers (2)

Maarten Bodewes
Maarten Bodewes

Reputation: 94038

Stream encryption does work for this, but even stream encryption is only working on bits. So you need to compress the text to fit in as few bits as possible. Using deflation would work in most cases, but may fail on shorter messages or messages that contain uncompressable data.

Another way is to compress your message into as few bits as possible yourself. E.g. the numbers 0..9 are ASCII 30h to 39h. But they may also be stored in binary form 0000 to 1001 binary. Packed BCD would be a good option for encoding numbers. Mathematic majors would immediately see you can use groups and division for minimum storage requirements, but that may add quite a lot of CPU resources (never mind the fun developing that solution). Once you have the shortest binary representation you encrypt with the stream cipher.

So now you have this nice short binary representation. Hopefully it will fit into the SMS message. If not, you need to encode the resulting binary representation.

Basically, what you need to do is:

send = Send(EncodeBin(Encrypt(EncodeTxt(plain))))

then

plain = DecodeTxt(Decrypt(DecodeBin(Receive(send))))

But don't let that stop you :)

Upvotes: 1

SKi
SKi

Reputation: 8476

Check stream chiphers (like RC4). Those won't increase space need. Encrypted data has same length than plain data.

If you want to encrypt 7-bit text message witch can be 160 chars. Then those does not help. But if maximum length of plain text is 140 bytes, then those can be used.

Upvotes: 1

Related Questions