2019-03-28 10:28:07 +0200 received badge ● Famous Question (source) 2019-03-28 10:28:07 +0200 received badge ● Notable Question (source) 2017-05-07 17:03:21 +0200 received badge ● Famous Question (source) 2016-03-01 19:01:22 +0200 received badge ● Notable Question (source) 2015-06-12 16:19:26 +0200 received badge ● Popular Question (source) 2015-06-08 21:44:29 +0200 asked a question worksheet to console ? Hi I have written a code in sageworksheet format, it runs nice and smooth on sagecloud, but I have one problem : I want to make it more interactive so the user can enter the parameters by himself, so I'm willing to convert this into a sage script or a pyhton script, I have installed sage on my ubuntu machine, again the code runs on the notebook but not on the console it gives me some syntax error on " P " All I want is to make it run as a Python script or Sage script so I can use input function to ask users to enter the parameters ! Here is the code : P. = PolynomialRing(ZZ); def bezout(f,g): P. = PolynomialRing(QQ) f = f+x-x g = g+x-x e=xgcd(f,g) gcd=e u=e v=e return (u,v,gcd) def polymod(f,q): P. = PolynomialRing(QQ) f = f c = f.coefficients(sparse=False) N = len(c) for i in range(N): c[i] = Rational(c[i]).mod_ui(q); p = sum(c[i]*(x^(i)) for i in range(N)); return p def center(f,q): u = q/2 v = -u c = f.coefficients(sparse=False) N = len(c) for i in range(N): if c[i]u: c[i] = c[i] - q; else: c[i] = c[i]; p = sum(c[i]*(x^(i)) for i in range(N)); return p class Ntru: N = None p = None q = None d = None f = None g = None h = None fp = None fq = None Phi = None def __init__(self,N,p,q,d): self.N = N self.p = p self.q = q self.d = d v = self.N self.Phi = x^v -1 def test(self): if not is_prime(self.N): print "N n est pas premier, pensez a changer ce parametre" return False if gcd(self.N,self.p) != 1: print "N et p ne sont pas premiers entre eux, pensez a changer ces parametres" return False if gcd(self.N,self.q) != 1: print "N et q ne sont pas premiers entre eux, pensez a changer ces parameres" return False if self.q <= (6*self.d+1)*self.p : print "q doit etre superieur a (6d+1)*p " return False return True def genPublicKey(self,f_new,g_new): self.f = f_new self.g = g_new (b_f,b_phi,bz) = bezout(self.f,self.Phi) self.fp = polymod(b_f,self.p) self.fq = polymod(b_f,self.q) self.h = polymod((self.fq*self.g).quo_rem(self.Phi),self.q) if not self.test(): print "le cryptage ne peut s effectuer avec ces parametres !" quit() def encrypt(self,message,rand): if self.h!=None: temp=(self.p*rand*self.h + message).quo_rem(self.Phi) e=polymod(temp,self.q) return e else: print "Impossible de faire le cryptage : la cle n a pas encore ete generee" print "Veuillez en generer une avec la fonction genPublicKey" def ... 2015-06-01 17:36:13 +0200 received badge ● Popular Question (source) 2015-05-28 01:34:33 +0200 commented question bezout coefficients ? thank you ! 2015-05-27 19:09:56 +0200 received badge ● Editor (source) 2015-05-27 19:08:47 +0200 asked a question Bezout coefficients for Polynomials I want to find the bezout coefficient for those 2 polynomials : f = 1+x-x^2-x^4+x^5 and g = -1+x^2+x^3-x^6 when I use the gcd function in sage the output is : sage: gcd(f,g) sage: 1  but when I use xgcd(f,g) it gives me the following : (-27, 9x^5 - 18x^2 - 9x - 9, 9x^4 - 9x^3 - 18x + 18) I want xgcd to give me 1 instead of -27 so the polynomials will be the bezout coefficients P.S: I can't divide the polynomials by -27 because i'm working in ZZ 2015-05-27 19:06:55 +0200 asked a question bezout coefficients ? I want to find the bezout coefficient for those 2 polynomials : $f = 1+x-x^2-x^4+x^5$ and $g = -1+x^2+x^3-x^6$ when I use the gcd function in sage the output is : sage: gcd(f,g) sage: 1  but when I use xgcd(f,g) it gives me the following : ($-27$, $9x^5 - 18x^2 - 9x - 9$, $9x^4 - 9x^3 - 18x + 18$) I want xgcd to give me 1 instead of -27 so the polynomials will be the bezout coefficients P.S: I can't divide the polynomials by -27 because i'm working in ZZ