Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#28 Re: Euler Avenue » Weird modular multiplicative inverse » 2010-07-24 06:19:22

i have a small function i wrote in my personal math library.

def pair_coprime(numberlist):
	for x in numberlist:
		for y in xrange(len(numberlist)):
			if x != numberlist[y]:
				out = gcd(x,numberlist[y])
				if out != 1:
					return False #Some values are not coprime
	return True #List is pairwise coprime

it could be faster, i think, but for now, its alright

i have another question:
can (a^b * c^d) mod e be done as [(a^b mod e) * (c^d mod e)] mod e? if not, whats an efficient way to do this on a computer? the exponentiation by squaring thing will still go through the second equation

#29 Re: Euler Avenue » Weird modular multiplicative inverse » 2010-07-24 06:01:48

interesting...

i think i found another way: im going to get a random number and add 1 until the value is coprime to k

#30 Re: Euler Avenue » Weird modular multiplicative inverse » 2010-07-24 05:43:30

yes, but what if the upper limits are large?

do you know java?
http://liris.cnrs.fr/~ohasan/pprs/paillierdemo/Paillier.java

#31 Re: Euler Avenue » Weird modular multiplicative inverse » 2010-07-24 05:11:13

Thanks! now... how do i chose random integers from the set? i cant list out all the possible values every time. the O(n) would be ridiculous

#32 Re: Euler Avenue » Weird modular multiplicative inverse » 2010-07-24 04:28:33

the z, but this one also has a * next to it

#33 Re: Euler Avenue » Weird modular multiplicative inverse » 2010-07-23 12:27:05

quick thing: what does it mean when a integer symbol has a little star next to it? i cant seem to remember and cant think of how to search for it

#34 Re: Euler Avenue » Weird modular multiplicative inverse » 2010-07-23 11:38:00

im trying to write the Paillier cryptosystem. it seems easy enough, but its not working for some reason or another

#36 Re: Euler Avenue » Weird modular multiplicative inverse » 2010-07-23 09:18:23

edit: okay. i fail. i reversed the values. sorry for wasting your time

#37 Euler Avenue » Weird modular multiplicative inverse » 2010-07-23 07:19:54

calccrypto
Replies: 25

im trying to get the value of mu as shown in the stuff below, but im getting a completely different value

from http://liris.cnrs.fr/~ohasan/pprs/paillierdemo/index.html?pt1=10&pt2=21  (dont bother going there. the values change everytime)

# Select two random and distinct primes p and q of length k/2
p = 33581                                    <-- given
q = 53299                                    <-- given

# Compute n = p*q
n = 1789833719                                    <-- got this

# Compute lambda = lcm(p-1,q-1) = (p-1)*(q-1) / gcd(p-1,q-1)
lambda = 894873420                                    <-- got this

# Select a random integer g in Z*_{n^2}
g = 3082513844323755387                                    <-- given

# Compute mu = (L(g^lambda mod n^2))^-1 mod n, where L(u) = (u-1)/n                                    <-- im getting the inside stuff to be 1323971239912197708, L(u) = 739717453
mu = 1430230768

im getting mu to be 148619716. yet, the values produced work, while mine dont. what am i doing wrong?

#41 Re: Coder's Corner » What's a fast way to fulfill this condition? » 2010-07-19 06:23:27

I think the bottleneck is the testing itself. Oh well. No matter. I'll eventually figure this out.

Thanks bobbym

#42 Re: Coder's Corner » What's a fast way to fulfill this condition? » 2010-07-19 02:47:44

yep, which is why i want to try to speed up the testing a bit

#43 Re: Coder's Corner » What's a fast way to fulfill this condition? » 2010-07-18 13:43:49

no. i guess my comment was a bit vague

i might as well put the real code:

	p = randint(3, 2**L)
	p = q * (1 + p/q) + 1
	while MillerRabin(p) == False:                # prime = True, composite = False
		p = p + q

miller rabin is not what im creating. rather, it is another function that im using to test my p values, and it is the probabilistic test.

the L value can be 1024,2048, or 3072

#44 Re: Coder's Corner » What's a fast way to fulfill this condition? » 2010-07-18 13:18:20

well the entire code block is just a pseudo code, but randint (which is also a legitimate command) is supposed to returns a random integer between a and b, inclusive. the real code is barely any different

#45 Coder's Corner » What's a fast way to fulfill this condition? » 2010-07-18 13:03:18

calccrypto
Replies: 15

given:

Choose an L-bit prime modulus p such that p–1 is a multiple of q.

what is the best way to find p that is both prime and (p-1) mod q = 0? right now, im doing the brute force way of:

q is some big prime number
p = randint(3,2^L)                     # i guess the bit size can be ignored for the moment
p = q * (1 + p/q) + 1                  # since the values are ints, p/q is really floor(p/q). this gets a value that is a (multiple of q) +1, like q = 7 ->p = 3*7 +1 = 22

while p is not prime:                  # the testing function is MillerRabin
   p = p - q

testing is taking forever, but since im terrible at reading other people's codes, ive been unable to find out how other people programed this to work very fast

#47 Re: Help Me ! » Seemingly Simple Summation » 2010-06-20 07:45:48

i finally figured it out:
change r to little endian
do the equation i put in the first post
add the little endian of AES_k(n) and mod 2^128
change to little endian

#48 Re: Help Me ! » Seemingly Simple Summation » 2010-06-20 05:34:29

oh. whoops. i forgot to change r to little endian. wow. i fail

edit:

what an annoying person. this guy changes the values to little endian so many times its not even funny

#49 Re: Help Me ! » Seemingly Simple Summation » 2010-06-20 05:26:49

nope.
im looking at this other guy's code, and somehow he's getting the correct answer even though it looks like im doing the same thing as he is:

  tot = 0
  for i in range(q):
    sub = msg[i*16 : i*16+16] + "\x01"              # [backwards(0124bcb676f4f39395d883fb0f19ea3c66),  backwards( 01366165d05266af8cdb6aa27e1079e6d7)]
    sub += (17 - len(sub)) * "\x00"
    num = str2num_littleend(sub)          # c1       =  0x124bcb676f4f39395d883fb0f19ea3c66,            c2       =  0x1366165d05266af8cdb6aa27e1079e6d7
    tot = (tot + num) * rval                        # same as c1 * r^q + c2 * r^(q-1)+ ... cq*r right?
  tot = tot % mod1305

Board footer

Powered by FluxBB