On Wednesday 17 September 2008, vpv wrote:
> I've successfully created a 4x4 4-bit variant of SR
>
> sage: sr = mq.SR(1,4,4,4,allow_zero_inversions=True)
> sage: sr
> SR(1,4,4,4)
>
> Next I would like to create a plaintext/key pair, which is composed of
> variables (say x0,x1,...,x15,k0,k1,...,k15) rather than actual values
> (eg. 0,1,...,1,0,0,0,1,1). How can I do that?
>
> P.S. naturally I assume that x0,...x15,k0,...,k15 are elements in
> GF(2) so that eg. x0+x0=0 and x0*x0=x0

Hi there,

I don't 100%ly get your question, since the key bits are by default 
represented as variables not constants, so sr.polynomial_system() not fix 
them. As for the plaintext/ciphertext bits, it isn't supported in a 
straight-forward way (i.e. as an option) but here is a way to accomplish 
this.

First we create some SR instance: 

sage: sr = mq.SR(1,1,1,4, gf2=True, polybori=True)
sage: sr
SR(1,1,1,4)

Now we build a ring to hold the additional variables

sage: bs = sr.r*sr.c*sr.e
sage: Pv = ["P%d"%i for i in range(bs)]
sage: Cv = ["C%d"%i for i in range(bs)]
sage: vn = Pv + list(sr.R.variable_names()) + Cv
sage: R2 = BooleanPolynomialRing(sr.R.ngens() + 2*bs, vn, sr.R.term_order())
sage: print R2.repr_long()
Polynomial Ring
  Base Ring : Finite Field of size 2
       Size : 36 Variables
   Block  0 : Ordering : degrevlex
              Names    : P0, P1, P2, P3, k100, k101, k102, k103, x100, x101, 
x102, x103, w100, w101, w102, w103, s000, s001, s002, s003, k000, k001, k002, 
k003, C0, C1, C2, C3

Create vectors holding variables:

sage: Pv = Matrix(R2, bs, 1, R2.gens()   [:bs] )
sage: Cv = Matrix(R2, bs, 1, R2.gens() [-bs:] )

... and create the equation system:

sage: sr.R = R2 # this is necessary
sage: system = []
sage: for i in range(sr.n+1):
...       system.append( sr.round_polynomials(i, Pv, Cv) )
...       system.append( sr.key_schedule_polynomials(i) )
sage: F = mq.MPolynomialSystem(R2, system)
sage: F
Polynomial System with 36 Polynomials in 28 Variables

We can now verify the system like this:

Choose a random plaintext/key pair:

sage: P = sr.random_vector()
sage: K = sr.random_vector()
sage: C = sr(P,K)

subsitute P and C:

sage: d1 = dict(zip(Pv.column(0),P.column(0)))
sage: d2 = dict(zip(Cv.column(0),C.column(0)))
sage: F.subs(d1)
sage: F.subs(d2)
sage: F.groebner_basis()

The output should match the chosen "K".

I agree that the above is more complicated than it has to be.

Cheers,
Martin

-- 
name: Martin Albrecht
_pgp: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8EF0DC99
_www: http://www.informatik.uni-bremen.de/~malb
_jab: [EMAIL PROTECTED]


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to