Modular exponentation with multiple exponents?

I need to do a^b^c^d^e mod f

I can do a^b mod f like this

a.to_bn.mod_exp(b,f)

but I have no clue how to do it when it is a^b^c^d^e mod f, and I can’t
seem to find anyway to do it in ruby or with math in general,

anyone care to point me in the right direction please? thanks!

Hi,

a ** b ** c ** d ** e % f

should solve your problem

lol

@ roob noob:

Have you already had a look at how “normal” modular expontation is
implemented?
http://rosettacode.org/wiki/Modular_exponentiation#Ruby

// Well, I guess that doesn’t help. It’s seems to be rather a problem
for a math forum.

Yes it seems like a problem for a math forum unless there is a ruby
method like a.to_bn.mod_exp(b,f) that allows for multiple exponents to
be specified…but I doubt I will be so lucky.

Jimmy Petersen wrote in post #1070154:

Hi,

a ** b ** c ** d ** e % f

should solve your problem

I thought it might be so simple but the numbers are enormous and that
will freeze everything and never get done. Each of the numbers are one
thousand bits long. Are you sure that is what is being asked for when
they say a ^ b c d e mod n (with a big a and the other letters above it
like normal exponentiation) I might have not even written it correctly
as a ^ b ^ c ^ d ^ e % f but that is how I am reading it.

Why do you even need it? Implementing your own cryptography as a layman
is not really a good idea.

Sorry, but this simply makes no sense. A professional certainly would
write the code himself rather than try to make something out of yours
(no offense, but this is not high school math).

So if this is a serious project, hire someone to do it. Otherwise you
obviously don’t need it.

Half baked security is probably even worse than no security at all,
because it provides you with a false feeling of safety.

I need it to implement a cryptographic accumulator, I know it is a bad
idea to implement my own cryptography, but unfortunately there is not
such a thing already made that I have any access to. Also, I plan to get
it reviewed thoroughly by not-laymen before I use it for anything. I
think as long as I don’t assume that I do it correctly, nothing bad can
come from it , and if I do it partially correctly I am more likely to
get someone skilled at crypto to fix my mistakes (or point them out to
me) than I am to get them to build the entire thing for me from scratch
(which wouldn’t be fun for me anyway :P)

Jan E. wrote in post #1070171:

Sorry, but this simply makes no sense. A professional certainly would
write the code himself rather than try to make something out of yours
(no offense, but this is not high school math).

So if this is a serious project, hire someone to do it. Otherwise you
obviously don’t need it.

Half baked security is probably even worse than no security at all,
because it provides you with a false feeling of safety.

If I follow a specification and do plenty of research, I don’t see why
it will be less safe to use it after cryptographers confirm it is
properly implemented, than if they write it themselves and claim it is
properly implemented.

I am not interested in hiring someone to do it and I have plenty
contacts who know crypto well and who will look over code I write for me
and tell me where my mistakes are, but who are not interested in writing
entire algorithms for me (and equally I am not interested in asking them
to do such a thing, I feel bad enough to ask questions like this and I
try my best to show substantial effort before requesting assistance).

I found the answer to my question, it is asking for

((((a ^ b) mod f) ^ c) mod f)) ^ d) mod f)

which is equal to a^bcd*etc mod f (which is probably how I should have
read it in the first place, doh)

So I can easily implement that piece of the puzzle now, and additionally
know that I have done so with a correct understanding of what the math
calls for.

anyway, I apologize for a question that had only a minor relation to
Ruby. However, I do think you are incorrect in thinking that a
thoroughly
researched project, implemented from a detailed specification and
reviewed by professionals, will certainly end up being worse than a
project made by someone who has already done the research to become a
professional. The only difference I see is that they would not need to
do as much focused research as I do , due to already having done it in a
more general sense.

Am 25.07.2012 23:21, schrieb roob noob:

Jan E. wrote in post #1070171:

Half baked security is probably even worse than no security at all,
because it provides you with a false feeling of safety.

[…]

I found the answer to my question, it is asking for

((((a ^ b) mod f) ^ c) mod f)) ^ d) mod f) etc (something I thought may
be the case, although I was by no means sure)

which is equal to a^bcd*etc mod f (which is probably how I should have
read it in the first place, doh)

What you probably really mean is: a^(bcd*…) mod f

You should be aware of the fact that (in Mathematics as well as in Ruby)
2^34 and 2^(34) [resp. 23*4 and 2(3*4)] are not the same.
Which kind of supports the point Jan is making.

Btw, there is also a huge(!) difference between 234 = 2**(34)
and (2
3)**4.

anyway I apologize for a question that had only a minor relation to
Ruby, however I do think you are wrong to think that a well researched
project implemented from a spec and reviewed by professionals will
certainly end up being worse than a project made by someone who has
already done the research to become a professional.

Regards,
Marcus

This is like a kid trying to build a plane after heaving read some
online tutorials. Yes, it might actually manage to put some parts
together. It might even have a friend who knows a bit about engineering
and intervenes when the kid has mounted the wings upside down. But I
think I wouldn’t want to fly in that plane.

Know your limits. :wink: