Permalink
Browse files

fixed loop to be ruby 1.9 compliant

  • Loading branch information...
James Zhang
James Zhang committed May 28, 2009
1 parent 4a4a96e commit 73cc04a5fe71e38c93de73240db0d664e93c861f
Showing with 14 additions and 7 deletions.
  1. +4 −0 History.txt
  2. +1 −0 Rakefile
  3. +9 −7 lib/crypt_tea/xxtea.rb
View
@@ -1,3 +1,7 @@
+=== 1.2.0 / 2009-05-27
+
+* Ruby 1.9 Compliant!
+
=== 1.1.0 / 2009-04-06
* BUGFIX
View
@@ -4,4 +4,5 @@ require './lib/crypt_tea.rb'
Hoe.new('crypt-tea', Crypt::XXTEA::VERSION) do |p|
p.developer('Jeff Smick', 'sprsquish@gmail.com')
+ p.developer('James Zhang', 'james@aftershocksf.com')
end
View
@@ -1,6 +1,6 @@
module Crypt
class XXTEA
- VERSION = '1.1.0'
+ VERSION = '1.2.0'
DELTA = 0x9E3779B9
def initialize(new_key)
@@ -79,9 +79,10 @@ def encrypt(plaintext)
sum = int32(sum + DELTA)
e = sum >> 2 & 3
- n.times do |p|
- y = v[p + 1];
- z = v[p] = int32(v[p] + mx(z, y, sum, p, e))
+ n.times do |i|
+ y = v[i + 1];
+ z = v[i] = int32(v[i] + mx(z, y, sum, i, e))
+ p = i
end
p += 1
@@ -108,9 +109,10 @@ def decrypt(ciphertext)
while (sum != 0) do
e = sum >> 2 & 3
- n.downto(1) do |p|
- z = v[p - 1]
- y = v[p] = int32(v[p] - mx(z, y, sum, p, e))
+ n.downto(1) do |i|
+ z = v[i - 1]
+ y = v[i] = int32(v[i] - mx(z, y, sum, i, e))
+ p = i
end
p -= 1

0 comments on commit 73cc04a

Please sign in to comment.