[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby version ot TEA (Tiny Encryption Alogrithm)?

james_b

6/7/2005 9:10:00 PM

Does anyone know of a pure-Ruby lib that implements the Tiny Encryption
Algorithm?


http://www.ftp.cl.cam.ac.uk/ftp/papers/djw-rmn/djw-rm...
http://www.simonshepherd.supanet.c...

I've been looking at porting a JavaScript version, but don't want to
reinvent the wheel.

Related question: The JavaScript version uses a shift right, zero fill
operation. Ruby seems to only offer signed shift-right. Is this the
case? Is there a Ruby version of shift right, zero fill someplace?

Thanks,


James

--

http://www.ru... - The Ruby Documentation Site
http://www.r... - News, Articles, and Listings for Ruby & XML
http://www.rub... - The Ruby Store for Ruby Stuff
http://www.jame... - Playing with Better Toys


5 Answers

Jeremy Hinegardner

6/8/2005 7:42:00 AM

0

On Wed, Jun 08, 2005 at 06:10:27AM +0900, James Britt wrote:
> Does anyone know of a pure-Ruby lib that implements the Tiny Encryption
> Algorithm?

I couldn't find one, and I happened to be a bit bored this evening... so
will this do?

If this code is going to be used to both encrypt and decrypt then it
should work. Not sure how it will interact well with other
implementations. The conversions of the encrypted longs to printable
text could be done in any number of manners. I took the easy route and
just converted the longs to hex. I would appreciate it if someone
double checked my implementation. And I'm sure there are speed
improvements. I went for readability.

enjoy,

-jeremy

--
========================================================================
Jeremy Hinegardner jeremy@hinegardner.org

james_b

6/8/2005 1:22:00 PM

0

Jeremy Hinegardner wrote:
> On Wed, Jun 08, 2005 at 06:10:27AM +0900, James Britt wrote:
>
>>Does anyone know of a pure-Ruby lib that implements the Tiny Encryption
>>Algorithm?
>
>
> I couldn't find one, and I happened to be a bit bored this evening... so
> will this do?

This just might do it. Thanks.

>
> If this code is going to be used to both encrypt and decrypt then it
> should work. Not sure how it will interact well with other
> implementations.

Well, I was looking to do the decryption using the JavaScript
implementation here:

http://www.movable-type.co.uk/scripts/TEA...

The two don't seem to play well together. But perhaps I can port the
Ruby to JavaScript. Or learn from your code and write my own Ruby
version of the block version of TEA.

Thanks,

James


Max Nickel

6/8/2005 2:10:00 PM

0

> Related question: The JavaScript version uses a shift right, zero fill
> operation. Ruby seems to only offer signed shift-right. Is this the
> case? Is there a Ruby version of shift right, zero fill someplace?

AFAIK Ruby only supports arithmetic, not logical right shift. But
logical right shift is quite easy to implement. Just shift the number of
bits and then mask the same number of the "front" bits.
For example, if you have a 32-Bit long number and want to shift one bit
& fill with zero you could do
i = (i >> 1) & 0x7FFFFFFF

irb(main):001:0> i = -3
=> -3
irb(main):002:0> 31.downto(0) do |n| print i[n] end
11111111111111111111111111111101=> 31
irb(main):003:0> i = (i >> 1) & 0x7FFFFFFF
=> 2147483646
irb(main):004:0> 31.downto(0) do |n| print i[n] end
01111111111111111111111111111110=> 31
irb(main):005:0>

regards
/max

james_b

6/8/2005 2:32:00 PM

0

Max Nickel wrote:
>>Related question: The JavaScript version uses a shift right, zero fill
>>operation. Ruby seems to only offer signed shift-right. Is this the
>>case? Is there a Ruby version of shift right, zero fill someplace?
>
>
> AFAIK Ruby only supports arithmetic, not logical right shift. But
> logical right shift is quite easy to implement. Just shift the number of
> bits and then mask the same number of the "front" bits.
> For example, if you have a 32-Bit long number and want to shift one bit
> & fill with zero you could do
> i = (i >> 1) & 0x7FFFFFFF

Ah. Yes.
Thanks!


James


Jeremy Hinegardner

6/9/2005 5:48:00 AM

0

On Wed, Jun 08, 2005 at 10:21:39PM +0900, James Britt wrote:
> >
> >If this code is going to be used to both encrypt and decrypt then it
> >should work. Not sure how it will interact well with other
> >implementations.
>
> Well, I was looking to do the decryption using the JavaScript
> implementation here:
>
> http://www.movable-type.co.uk/scripts/TEA...
>
> The two don't seem to play well together. But perhaps I can port the
> Ruby to JavaScript. Or learn from your code and write my own Ruby
> version of the block version of TEA.

Ah yes, see I didn't even realize all the different variants. I just
did some searching on TEA and did the New Variant non-block version.
I probably won't get to it for the next week or so, but I think I could
probably put together a full suite of TEA variants as a ruby module.
That could be a nice fun couple of evenings.

enjoy,

-jeremy

--
========================================================================
Jeremy Hinegardner jeremy@hinegardner.org