```-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I have the following code to detirmine even-ness for an integer by
snooping at its low-order bit:

if n==0
print "Even!\n"
else
print "Odd!\n"
end

This works fine on Intel machines, which are little-endian. I am
wondering, though, what will happen when I try to run it on a Sun
(which is big-endian)? Do bits have a pre-defined order?

For those wondering why I did this, here is a mod_exp routine
for calculating z**n % q for very large numbers such as are used
in public key encryption:

# work even once we promote ourself :-). Knuth's Algorithm A,
# from p462 of latest edition of Seminumerical Algorithms.

module Crypto_math
def mod_exp(n,q)
counter=0
n_p=n.clone  # N
y_p=1        # Y
z_p=self.clone  # Z
while n_p != 0
# if N is odd, multiply Y * Z
# Whoa, we can access the bits of our integer as if they were
# an array! But will this work on big-endian machines?
if n_p==1
y_p=(y_p*z_p) % q
end
# divide n_p by 2. Whoa, shifts!
n_p = n_p >> 1
# and square Z.
z_p = (z_p * z_p) % q
counter += 1
end
return y_p
end

class Bignum
include Crypto_math
end

class Integer
include Crypto_math
end

To use it, you type something like:

2.mod_exp(xx,p)

for example to calculate a Diffie-Hellman public key,
where 2 is a generator for the prime field p (a prime field of
order 2^1024) and xx is a 1024-bit number that is relatively prime to xx-1
(I have coded a gcd(i) routine too in order to test for relative prime-ness,
as well as a random routine for obtaining such numbers in the first
place, but we are getting too long for a USENET message).
It appears to work on both Windows and Linux, I get the same answer that
I get from GNU 'dc' and from lib_gmp/"C".

If the code is clumsy please forgive me, that was the first
code I ever wrote in Ruby. I am sure that some will tell me how
I could use an iterator or other Ruby specialness to make
it tighter, but the wonder is that it works at all, and works quite
well actually (faster than GNU 'dc', which is written entirely in "C",
and almost as fast as the GNU MP library, which has much assembly
language in it, further proving that algorithms are more important
than language for many problems).

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE7a17x3DrrK1kMA04RAlGYAJ4qApsTHT+x8Q3G5r9ZY7OE5xSUygCaA30y