Example #1
0
 def time_information_set_steps():
     before = time.clock()
     while True:
         I = sample(range(n), k)
         Gi = G.matrix_from_columns(I)
         try:
             Gi_inv = Gi.inverse()
         except ZeroDivisionError:
             continue
         return time.clock() - before
 def time_information_set_steps():
     before = time.clock()
     while True:
         I = sample(range(n), k)
         Gi = G.matrix_from_columns(I)
         try:
             Gi_inv = Gi.inverse()
         except ZeroDivisionError:
             continue
         return time.clock() - before
Example #3
0
    def decode(self, r):
        r"""
        The Lee-Brickell algorithm as described in the class doc.

        Note that either parameters must be given at construction time or
        :meth:`sage.coding.information_set_decoder.InformationSetAlgorithm.calibrate()`
        should be called before calling this method.

        INPUT:

        - `r` -- a received word, i.e. a vector in the ambient space of
          :meth:`decoder.Decoder.code`.

        OUTPUT: A codeword whose distance to `r` satisfies ``self.decoding_interval()``.

        EXAMPLES::

            sage: M = matrix(GF(2), [[1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0],\
                                     [0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1],\
                                     [0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0],\
                                     [0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1],\
                                     [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1]])
            sage: C = codes.LinearCode(M)
            sage: from sage.coding.information_set_decoder import LeeBrickellISDAlgorithm
            sage: A = LeeBrickellISDAlgorithm(C, (2,2))
            sage: c = C.random_element()
            sage: Chan = channels.StaticErrorRateChannel(C.ambient_space(), 2)
            sage: r = Chan(c)
            sage: c_out = A.decode(r)
            sage: (r - c).hamming_weight() == 2
            True
        """
        import itertools
        from sage.all import sample
        C = self.code()
        n, k = C.length(), C.dimension()
        tau = self.decoding_interval()
        p = self.parameters()['search_size']
        F = C.base_ring()
        G = C.generator_matrix()
        Fstar = F.list()[1:]
        while True:
            # step 1.
            I = sample(range(n), k)
            Gi = G.matrix_from_columns(I)
            try:
                Gi_inv = Gi.inverse()
            except ZeroDivisionError:
                # I was not an information set
                continue
            Gt = Gi_inv * G
            #step 2.
            y = r - vector([r[i] for i in I]) * Gt
            g = Gt.rows()
            #step 3.
            for pi in range(p + 1):
                for A in itertools.combinations(range(k), pi):
                    for m in itertools.product(Fstar, repeat=pi):
                        e = y - sum(m[i] * g[A[i]] for i in range(pi))
                        errs = e.hamming_weight()
                        if errs >= tau[0] and errs <= tau[1]:
                            return r - e
    def decode(self, r):
        r"""
        The Lee-Brickell algorithm as described in the class doc.

        Note that either parameters must be given at construction time or
        :meth:`sage.coding.information_set_decoder.InformationSetAlgorithm.calibrate()`
        should be called before calling this method.

        INPUT:

        - `r` -- a received word, i.e. a vector in the ambient space of
          :meth:`decoder.Decoder.code`.

        OUTPUT: A codeword whose distance to `r` satisfies ``self.decoding_interval()``.

        EXAMPLES::

            sage: M = matrix(GF(2), [[1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0],\
                                     [0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1],\
                                     [0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0],\
                                     [0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1],\
                                     [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1]])
            sage: C = codes.LinearCode(M)
            sage: from sage.coding.information_set_decoder import LeeBrickellISDAlgorithm
            sage: A = LeeBrickellISDAlgorithm(C, (2,2))
            sage: c = C.random_element()
            sage: Chan = channels.StaticErrorRateChannel(C.ambient_space(), 2)
            sage: r = Chan(c)
            sage: c_out = A.decode(r)
            sage: (r - c).hamming_weight() == 2
            True
        """
        import itertools
        from sage.all import sample
        C = self.code()
        n, k = C.length(), C.dimension()
        tau = self.decoding_interval()
        p = self.parameters()['search_size']
        F = C.base_ring()
        G = C.generator_matrix()
        Fstar = F.list()[1:]
        while True:
            # step 1.
            I = sample(range(n), k)
            Gi = G.matrix_from_columns(I)
            try:
                Gi_inv = Gi.inverse()
            except ZeroDivisionError:
                # I was not an information set
                continue
            Gt = Gi_inv * G
            #step 2.
            y = r - vector([r[i] for i in I]) * Gt
            g = Gt.rows()
            #step 3.
            for pi in range(p+1):
                for A in itertools.combinations(range(k), pi):
                    for m in itertools.product(Fstar, repeat=pi):
                        e = y - sum(m[i]*g[A[i]] for i in range(pi))
                        errs = e.hamming_weight()
                        if  errs >= tau[0] and errs <= tau[1]:
                            return r - e