1 Introduction

Let q = p m and \(\phantom {\dot {i}\!}{\mathbb F}_{q}\) denote the finite field with q elements, where p is a prime and m is a positive integer. An n, k, d] linear code \(\phantom {\dot {i}\!}{\mathcal C}\) over \(\phantom {\dot {i}\!}{\mathbb F}_{p}\) is a k-dimensional subspace of \(\phantom {\dot {i}\!}{{\mathbb F}_{p}^{n}}\) with minimum (Hamming) distance d. Let A i denote the number of codewords with Hamming weight i in a code \(\phantom {\dot {i}\!}{\mathcal C}\) of length n. The weight enumerator of \(\phantom {\dot {i}\!}{\mathcal C}\) is defined by

$$1 + A_{1}z + A_{2}z^{2} + {\cdots} + A_{n}z^{n}. $$

Accordingly, the sequence (1,A 1,⋯ ,A n ) is called the weight distribution of \(\phantom {\dot {i}\!}{\mathcal C}\). Clearly, the weight distribution gives the minimum distance of the code, and thus the error correcting capability. Moreover, the weight distribution of a code allows the computation of the error probability of error detection and correction with respect to some error detection and error correction algorithms (see [14] for details). Thus the study of the weight distribution of a linear code is important in both theory and applications.

A code \(\phantom {\dot {i}\!}{\mathcal C}\) is said to be a t-weight code if the number of nonzero A i in the sequence (A 1,A 2,⋯ ,A n ) is equal to t. Linear codes with few weights have applications in secret sharing schemes [1, 3, 18], authentication codes [5, 6], and association schemes [2], in addition to their applications in consumer electronics, communication and data storage systems. They are also closely related with strongly regular graphs and combinatorial design. An n, k, d] linear code \(\phantom {\dot {i}\!}{\mathcal C}\) is called optimal if its parameters n, k and d meet a bound on linear codes [13]. An n, k, d] linear code \(\phantom {\dot {i}\!}{\mathcal C}\) is called almost optimal if n, k, d + 1] meets a bound on linear codes [13].

Design of (almost) optimal linear codes with few weights has been an interesting research topic in coding theory. Much progress has been made in recent years. One of known approaches for obtaining such linear codes is based on subsets of a finite field and the trace function over this field. Specifically, let D = {d 1,d 2,⋯,d n } be a subset of \(\phantom {\dot {i}\!}{\mathbb F}_{q}^{*}\), a linear code of length n over \(\phantom {\dot {i}\!}{\mathbb F}_{p}\) can be obtained as

$$ {\mathcal C}_{D}=\left\{\left( {\text{Tr}_{1}^{m}}(ad_{1}), {\text{Tr}_{1}^{m}}(ad_{2}), {\cdots} , {\text{Tr}_{1}^{m}}(ad_{n})\right) : a \in {\mathbb F}_{q}\right\}, $$
(1)

where \(\phantom {\dot {i}\!}{\text {Tr}_{1}^{m}}\) is the absolute trace function from \(\phantom {\dot {i}\!}{\mathbb F}_{q}\) to \(\phantom {\dot {i}\!}{\mathbb F}_{p}\) and D is called the defining set of this code. It turns out in [7, 8] that this approach is very promising in the sense that it can generate many (almost) optimal linear codes with a few weights if the subset D is appropriately chosen. This is further confirmed by a number of recent papers [11, 12, 17].

An objective of this paper is to construct a class of two-weight linear codes over \(\phantom {\dot {i}\!}{\mathbb F}_{p}\) with new parameters using the approach mentioned above. They are optimal or almost optimal linear codes in many cases. Another objective of this paper is to study the weight distribution and the dual of this class of linear codes. Thanks to some known results on Kloosterman sums over finite fields, the length and weight distribution of this class of linear codes have a closed-form expression, and are completely determined when p = 2 and p = 3. The parameters of its dual are also determined which are optimal or almost optimal in the binary case.

2 Preliminaries

Throughout this paper, we adopt the following notations unless otherwise stated:

  • p is a prime and m = 2k, where k is a positive integer with k > 2.

  • q = p m and r = p k.

  • \(\phantom {\dot {i}\!}\text {Tr}_{\ell _{1}}^{\ell _{2}}(x)\) is the trace function from the finite field \(\phantom {\dot {i}\!}{\mathbb F}_{p^{\ell _{2}}}\) to \(\phantom {\dot {i}\!}{\mathbb F}_{p^{\ell _{1}}}\) for any positive integers 1| 2.

  • χ is the canonical additive character on \(\phantom {\dot {i}\!}{\mathbb F}_{q}\), i.e., \(\phantom {\dot {i}\!}\chi (x)=e^{2\pi \sqrt {-1} {\text {Tr}_{1}^{m}}(x)/ p}\) for any \(\phantom {\dot {i}\!}x\in {\mathbb F}_{q}\).

  • For any positive integer |m, χ is the canonical additive character on \(\phantom {\dot {i}\!}{\mathbb F}_{p^{\ell }}\), i.e., \(\phantom {\dot {i}\!}\chi _{\ell }(x)=e^{2\pi \sqrt {-1} \text {Tr}_{1}^{\ell }(x)/ p}\) for any \(\phantom {\dot {i}\!}x\in {\mathbb F}_{p^{\ell }}\).

Let α be a generator of \(\phantom {\dot {i}\!}{\mathbb F}_{q}^{*}\) and β = α r−1. Let Δ be the cyclic group generated by β and Γ = {α j : 0 ≤ jr}. The following results will be useful to prove our main results.

Fact 1

With notations defined above, we have

  1. 1.

    {v r−1 : v ∈ Γ} = Δ; and

  2. 2.

    for each \(\phantom {\dot {i}\!}x \in {\mathbb F}_{q}^{*}\) , it has a unique decomposition as x = uv, where \(\phantom {\dot {i}\!}u \in {\mathbb F}_{r}^{*}\) and v ∈ Γ.

Lemma 1

For any given \(\phantom {\dot {i}\!}a\in {\mathbb F}_{q}^{*}\) , there is one and only one v a ∈ Γ such that

$${\text{Tr}_{k}^{m}}(av_{a})=0. $$

Proof

By Fact 1, x has a unique decomposition as x = u v, where \(\phantom {\dot {i}\!}u \in {\mathbb F}_{r}^{*}\) and v ∈ Γ. Therefore \(\phantom {\dot {i}\!}{\text {Tr}_{k}^{m}}(x)={\text {Tr}_{k}^{m}}(uv)=u{\text {Tr}_{k}^{m}}(v)\) which implies that the number of solutions \(\phantom {\dot {i}\!}x\in {\mathbb F}_{q}^{*}\) to \(\phantom {\dot {i}\!}{\text {Tr}_{k}^{m}}(x)=0\) is r − 1 times as the number of solutions v ∈ Γ to \(\phantom {\dot {i}\!}{\text {Tr}_{k}^{m}}(v)=0\). The conclusion then follows from the fact that the equation \(\phantom {\dot {i}\!}{\text {Tr}_{k}^{m}}(x)=0\) has q mk − 1 = r − 1 solutions in \(\phantom {\dot {i}\!}{\mathbb F}_{q}^{*}\). □

The length and weights of the linear code proposed in this paper will be expressed by means of the Kloosterman sums over finite field. For any \(\phantom {\dot {i}\!}a \in {\mathbb F}_{p^{\ell }}\), the Kloosterman sum over \(\phantom {\dot {i}\!}{\mathbb F}_{p^{\ell }}\) at the point a is defined by

$$K_{\ell}(a)= \sum\limits_{x \in {\mathbb F}_{p^{\ell}}^{*}} \chi_{\ell}\left( a x + \frac{1}{x}\right), $$

where is a positive integer with |m. The following bound on |K (a)| will be needed in the sequel.

Lemma 2

[ 16 ] With notations as above, we have

$$|K_{\ell}(a)|\leq 2\sqrt{p^{\ell}} $$

for any nonzero \(\phantom {\dot {i}\!}a\in {\mathbb F}_{p^{\ell }}\).

The following result on an incomplete exponential sum was firstly proven in [15] in the binary case and was extended to the nonbinary case by the last author in [10].

Lemma 3

For any \(\phantom {\dot {i}\!}a\in {\mathbb F}^{*}_{q}\) , we have

$$ \sum\limits_{x \in {\Delta}} \chi(ax) = - K_{k}\left( a^{2}\right). $$

The following lemma is due to Carlitz [4] and will be needed in the sequel.

Lemma 4

For any \(\phantom {\dot {i}\!}a \in {\mathbb F}_{q}^{*}\) ,

$$ K_{k}(a)= -\sum\limits_{t=0}^{\lfloor k/2\rfloor}(-1)^{k-t} \frac{k}{k-t} \binom{k-t}{t} p^{t}\left( K_{1}(a)\right)^{k-2t}. $$

3 A Class of Two-Weight Linear Codes

In this section, we shall study a class of linear codes with two weights. Following the notations in Section 2, let D be a subset of \(\phantom {\dot {i}\!}{\mathbb F}_{q}^{*}\) given by

$$ D = \left\{ x \in {\mathbb F}_{q}^{*} : {\text{Tr}_{1}^{m}}\left( x^{r-1}\right)=0\right\}. $$
(2)

According to (1), we naturally obtain a class of linear codes by using such D as the defining set. The following are the main results of this paper.

Theorem 1

Let \(\phantom {\dot {i}\!}{\mathcal C}_{D}\) be the linear code with defining set D in ( 2 ). Then \(\phantom {\dot {i}\!}{\mathcal C}_{D}\) is a two-weight linear code with parameters n,m] and weight distribution in Table 1 , where

Table 1 Weight distribution of \({\mathcal C}_{D}\)
$$\begin{array}{@{}rcl@{}} n=\frac{\left( p^{k}-1\right)\left( p^{k}+1+S\right)}{p} \end{array} $$
(3)

and

$$\begin{array}{@{}rcl@{}} S=\sum\limits_{t=0}^{\lfloor k/2\rfloor}(-1)^{k-t} \frac{k}{k-t} \binom{k-t}{t} p^{t}\sum\limits_{y\in {\mathbb F}_{p}^{*}}\left( K_{1}\left( y^{2}\right)\right)^{k-2t}. \end{array} $$
(4)

Proof

Define

$$ n = \left|\left\{ x \in {\mathbb F}_{q}^{*} : {\text{Tr}_{1}^{m}}\left( x^{r-1}\right)=0\right\}\right|. $$

By definition, the length of the code \(\phantom {\dot {i}\!}{\mathcal C}_{D}\) is equal to n which can be expressed in terms of character sums as

$$\begin{array}{@{}rcl@{}} n = \frac{1}p \sum\limits_{x \in {\mathbb F}_{q}^{*}} \sum\limits_{y \in {\mathbb F}_{p} }\zeta_{p}^{y{\text{Tr}_{1}^{m}}\left( x^{r-1}\right)}= \frac{1}p \sum\limits_{y \in {\mathbb F}_{p} } \sum\limits_{x \in {\mathbb F}_{q}^{*}}\chi\left( yx^{r-1}\right). \end{array} $$

Using Fact 1 and the fact that u r−1 = 1 for each \(\phantom {\dot {i}\!}u\in {\mathbb F}_{r}^{*}\), we have

$$\begin{array}{@{}rcl@{}} n&=& \frac{1}p \sum\limits_{y \in {\mathbb F}_{p} }\sum\limits_{u \in {\mathbb F}_{r}^{*}}\sum\limits_{v \in {\Gamma}}\chi\left( yv^{r-1}\right) \\ &=& \frac{p^{k}-1}p \sum\limits_{y \in {\mathbb F}_{p} }\sum\limits_{x \in {\Delta}}\chi(yx) \\ &=& \frac{p^{k}-1}p \left( p^{k}+1+\sum\limits_{y \in {\mathbb F}_{p}^{*} }\sum\limits_{x \in {\Delta}}\chi(yx)\right), \end{array} $$

where the last identity followed from the orthogonal property of the additive character χ. Applying Lemmas 3 and 4, we immediately get the formula in (3) for the length n of \(\phantom {\dot {i}\!}{\mathcal C}_{D}\).

We now calculate the Hamming weight of the codewords in \(\phantom {\dot {i}\!}{\mathcal C}_{D}\). Note that the codewords in \(\phantom {\dot {i}\!}{\mathcal C}_{D}\) are

$$\mathbf{c}_{a} = \left( {\text{Tr}_{1}^{m}}(ad_{1}), {\text{Tr}_{1}^{m}}(ad_{2}), {\cdots} , {\text{Tr}_{1}^{m}}(ad_{n})\right), ~a\in {\mathbb F}_{q}. $$

By definition, the Hamming weight of a codeword c a is equal to nN a , where

$$N_{a} = \left|\left\{ x \in {\mathbb F}_{q}^{*} : {\text{Tr}_{1}^{m}}\left( x^{r-1}\right)=0 ~\text{and} ~{\text{Tr}_{1}^{m}}(ax)=0\right\}\right|. $$

Clearly, N a = n if a = 0, and otherwise N a can be expressed in terms of character sums as

$$\begin{array}{@{}rcl@{}} N_{a} &=& \frac{1}{p^{2}} \sum\limits_{x \in {\mathbb F}_{q}^{*}} \left( \sum\limits_{y \in {\mathbb F}_{p} }\zeta_{p}^{y{\text{Tr}_{1}^{m}}\left( x^{r-1}\right)}\right) \left( \sum\limits_{z \in {\mathbb F}_{p} } \zeta_{p}^{z{\text{Tr}_{1}^{m}}(ax)}\right) \\ &=& \frac{1}{p^{2}} \sum\limits_{y \in {\mathbb F}_{p} } \sum\limits_{z \in {\mathbb F}_{p} }\sum\limits_{x \in {\mathbb F}_{q}^{*}}\chi\left( yx^{r-1}+zax\right). \end{array} $$

By Fact 1 again, we have

$$\begin{array}{@{}rcl@{}} N_{a} &=& \frac{1}{p^{2}} \sum\limits_{y \in {\mathbb F}_{p} } \sum\limits_{z \in {\mathbb F}_{p} }\sum\limits_{v \in {\Gamma}}\chi\left( yv^{r-1}\right)\sum\limits_{u \in {\mathbb F}_{r}^{*}}\chi(zauv) \\ &=& \frac{1}{p^{2}} \sum\limits_{y \in {\mathbb F}_{p} } \sum\limits_{z \in {\mathbb F}_{p} }\sum\limits_{v \in {\Gamma}}\chi\left( yv^{r-1}\right)\left( \sum\limits_{u \in {\mathbb F}_{r}}\chi(zauv)-1\right). \end{array} $$

Note that for any \(\phantom {\dot {i}\!}z \in {\mathbb F}_{p}, u \in {\mathbb F}_{r}^{*}, v \in {\Gamma }\) and \(\phantom {\dot {i}\!}a\in {\mathbb F}_{q}^{*}\),

$$\chi(zauv)=\chi_{k}\left( {\text{Tr}_{k}^{m}}(zauv)\right)=\chi_{k}\left( zu{\text{Tr}_{k}^{m}}(av)\right). $$

We then arrive at N a = N a,1N a,2, where

$$\begin{array}{@{}rcl@{}} N_{a,1}&=&\frac{1}{p^{2}} \sum\limits_{y \in {\mathbb F}_{p}} \sum\limits_{z \in {\mathbb F}_{p} } \sum\limits_{v \in {\Gamma}}\chi\left( yv^{r-1}\right)\sum\limits_{u \in{\mathbb F}_{r}}\chi_{k}\left( zu{\text{Tr}_{k}^{m}}(av)\right) \end{array} $$

and

$$\begin{array}{@{}rcl@{}} N_{a,2}&=&\frac{1}{p^{2}} {\sum}_{y \in {\mathbb F}_{p}} {\sum}_{z \in {\mathbb F}_{p} } {\sum}_{v \in {\Gamma}}\chi\left( yv^{r-1}\right)\\ &=& \frac{1}{p} {\sum}_{y \in {\mathbb F}_{p}} {\sum}_{v \in {\Gamma}}\chi\left( yv^{r-1}\right) \\ &=&\frac{1}{p}{\sum}_{y \in {\mathbb F}_{p}}{\sum}_{x \in {\Delta}}\chi(yx). \end{array} $$
(5)

Using the orthogonal property of the nontrivial additive characters and Fact 1, we have

$$\begin{array}{@{}rcl@{}} \begin{array}{lll} p^{2-k}N_{a,1}&=& \sum\limits_{y \in {\mathbb F}_{p}}\sum\limits_{z \in {\mathbb F}_{p} } \sum\limits_{\underset{z{\text{Tr}_{k}^{m}}(av)=0}{v \in {\Gamma}} }\chi\left( yv^{r-1}\right)\\ &=& \sum\limits_{y \in {\mathbb F}_{p}}\sum\limits_{v \in {\Gamma}} \chi\left( yv^{r-1}\right)+ \sum\limits_{y \in {\mathbb F}_{p}}\sum\limits_{z \in {\mathbb F}_{p}^{*} } \sum\limits_{\underset{z{\text{Tr}_{k}^{m}}(av)=0}{v \in {\Gamma}}} \chi\left( yv^{r-1}\right)\\ &=& \sum\limits_{y \in {\mathbb F}_{p}}\sum\limits_{v \in {\Gamma}} \chi\left( yv^{r-1}\right)+(p-1) \sum\limits_{y \in {\mathbb F}_{p}} \sum\limits_{\underset{\text{Tr}_{k}^{m}}(av)=0}{v \in {\Gamma}} \chi\left( yv^{r-1}\right)\\ &=& \sum\limits_{y \in {\mathbb F}_{p}}\sum\limits_{x \in {\Delta}}\chi(yx)+ (p-1)\sum\limits_{y \in {\mathbb F}_{p}}\chi\left( yv_{a}^{r-1}\right)\\ &=& \sum\limits_{y \in {\mathbb F}_{p}}\sum\limits_{x \in {\Delta}}\chi(yx) + (p-1\sum\limits_{y \in {\mathbb F}_{p}}\chi_{1}\left( y{\text{Tr}_{1}^{m}}\left( v_{a}^{r-1}\right)\right), \end{array}\\ \end{array} $$
(6)

where v a is the only one element in Γ such that \(\phantom {\dot {i}\!}{\text {Tr}_{k}^{m}}(av_{a})=0\) due to Lemma 1. It then follows from (5) and (6) that

$$\begin{array}{@{}rcl@{}} N_{a}&=& \frac{p^{k-1}-1}{p}\left( p^{k}+1+\sum\limits_{y \in {\mathbb F}_{p}^{*}}\sum\limits_{x \in {\Delta}}\chi(yx)\right)+p^{k-2}(p-1) \sum\limits_{y \in {\mathbb F}_{p}}\chi_{1}\left( y{\text{Tr}_{1}^{m}}\left( v_{a}^{r-1}\right)\right) \\ &=&\frac{\left( p^{k-1}-1\right)\left( p^{k}+1+S\right)}{p}+p^{k-2}(p-1) \sum\limits_{y \in {\mathbb F}_{p}}\chi_{1}\left( y{\text{Tr}_{1}^{m}}\left( v_{a}^{r-1}\right)\right), \end{array} $$
(7)

where the second identity followed from Lemmas 3 and 4, and S is given by (4). Note that the weight of the codeword c a is equal to nN a . By (7), the weight of c a takes the value

$$w_{1}= p^{k-2}(p-1)\left( p^{k} +1+S\right)-p^{k-1}(p-1) $$

if \(\phantom {\dot {i}\!}{\text {Tr}_{1}^{m}}\left (v_{a}^{r-1}\right ) = 0\), and otherwise takes the value

$$w_{2} = p^{k-2}(p-1)\left( p^{k}+1+S\right). $$

Note that w 2 > w 1 and S is an integer due to (3). In order to prove that the dimension of \(\phantom {\dot {i}\!}{\mathcal C}_{D}\) is equal to m, it is only necessary to prove that w 1 > 0 which is equivalent to proving that p k + 1 + Sp > 0. According to Lemma 3,

$$S=\sum\limits_{y \in {\mathbb F}_{p}^{*}}\sum\limits_{x \in {\Delta}}\chi(yx)= - \sum\limits_{y \in {\mathbb F}_{p}^{*} }K_{k}\left( y^{2}\right). $$

It then follows from Lemma 2 that

$$|S| \leq \sum\limits_{y \in {\mathbb F}_{p}^{*} }\left|K_{k}\left( y^{2}\right)\right| \leq 2(p-1)\sqrt{p^{k}}. $$

This together with the fact that S is an integer means that

$$\begin{array}{@{}rcl@{}} p^{k} +1+S-p &\geq p^{k} +1-p-2(p-1)\sqrt{p^{k}}. \end{array} $$

When k = 3, it is easily verified that p k + 1 + Sp > 0. When k > 3, we have

$$\begin{array}{@{}rcl@{}} p^{k} +1+S-p&\geq \left( \sqrt{p^{k}}-{p}\right)^{2}+2\sqrt{p^{k}}-p^{2}-p+1>0. \end{array} $$

Therefore, w 1 > 0 for any k ≥ 3. The discussion above shows that the dimension of \(\phantom {\dot {i}\!}{\mathcal C}_{D}\) is equal to m. It will be proved in Theorem 2 that the minimum weight of the dual code of \(\phantom {\dot {i}\!}{\mathcal C}_{D}\) is at least 2. By the Pless Power Moments (see [13], p. 259), we have

$$\left\{ \begin{array}{c} A_{w_{1}} + A_{w_{2}} = p^{m}-1, \\ w_{1}A_{w_{1}} + w_{2}A_{w_{2}} =(p-1)p^{m-1}n, \end{array}\right. $$

where \(\phantom {\dot {i}\!}A_{w_{1}}\) and \(\phantom {\dot {i}\!}A_{w_{2}}\) denote the number of codewords with weight w 1 and w 2 in \(\phantom {\dot {i}\!}{\mathcal C}_{D}\), respectively. Solving this simple equation system gives the weight distribution of \(\phantom {\dot {i}\!}{\mathcal C}_{D}\) in Table 1. This completes the proof. □

Remark 1

In Theorem 1, we get closed-form expressions of the length and weight distribution of \(\phantom {\dot {i}\!}{\mathcal C}_{D}\) using Kloosterman sums. One point that should be mentioned is that the defining set of \(\phantom {\dot {i}\!}{\mathcal C}_{D}\) has been used in [12]. In this sense, the linear code \(\phantom {\dot {i}\!}{\mathcal C}_{D}\) is not new. However, thanks to some known results on Kloosterman sums, we can determine the weight distribution of \(\phantom {\dot {i}\!}{\mathcal C}_{D}\) in the binary and ternary cases as shown below.

Remark 2

According to Theorem 1, in order to completely establish the weight distribution of \(\phantom {\dot {i}\!}{\mathcal C}_{D}\), it is sufficient to determine the value of the inner exponential sum in (4). It may be very hard in general. However, this can be done when p is small. In particular, when p = 2 and p = 3, we can get a more elegant expression for S. Note that K 1(1) = 1 when p = 2 and K 1(1) = −1 when p = 3. By (4), we immediately have

$$\begin{array}{@{}rcl@{}} S=\sum\limits_{t=0}^{\lfloor k/2\rfloor}(-1)^{k-t} \frac{k}{k-t} \binom{k-t}{t} 2^{t} \end{array} $$

when p = 2, and

$$\begin{array}{@{}rcl@{}} S=-2\sum\limits_{t=0}^{\lfloor k/2\rfloor}(-1)^{t} \frac{k}{k-t} \binom{k-t}{t} 3^{t} \end{array} $$

when p = 3. Plugging these values of S into Table 1, we then completely determine the weight distribution of the code \(\phantom {\dot {i}\!}{\mathcal C}_{D}\) in the binary and ternary cases.

The numerical experiments by Magma in the following examples agree with the weight distribution in Table 1.

Example 1

Let p = 2 and k = 4. Then the code \(\phantom {\dot {i}\!}{\mathcal C}_{D}\) has parameters 135,8,64] and weight enumerator 1 + 135y 64 + 120y 72. It is almost optimal due to [9].

Example 2

Let p = 3 and k = 3. Then m = 6 and q = 36, the code \(\phantom {\dot {i}\!}{\mathcal C}_{D}\) has parameters 104,6,54] and weight enumerator 1 + 104y 54 + 624y 72. According to [9], the minimum distance of the best known linear codes with length 104 and dimension 6 is 56.

Example 3

Let p = 3 and k = 4. Then the code \(\phantom {\dot {i}\!}{\mathcal C}_{D}\) has parameters 2560,8,1674] and weight enumerator 1 + 2560y 1674 + 4000y 1728.

4 The Dual of \({\mathcal C}_{D}\)

In this section, we shall discuss the dual code of the two-weight code in Theorem 1. The following theorem is the main result of this section.

Theorem 2

Let \(\phantom {\dot {i}\!}{\mathcal C}^{\bot }_{D}\) be the dual of the code \(\phantom {\dot {i}\!}{\mathcal C}_{D}\) . Then \(\phantom {\dot {i}\!}{\mathcal C}^{\bot }_{D}\) is a linear code with parameters n,n − m,d ], where d = 3 if p = 2 and d = 2 if p is an odd prime.

Proof

The dimension of the code \(\phantom {\dot {i}\!}{\mathcal C}_{D}^{\bot }\) follows from Theorem 1. By definition, D does not contain the zero element of \(\phantom {\dot {i}\!}{\mathbb F}_{q}\), thus the minimum distance of \(\phantom {\dot {i}\!}{\mathcal C}_{D}^{\bot }\) cannot be one.

When p = 2, any two distinct elements d i and d j in D satisfy d i + d j ≠0, where 1 ≤ ijn. This means that the minimum distance of \(\phantom {\dot {i}\!}{\mathcal C}_{D}^{\bot }\) cannot be 2. Note that \(\phantom {\dot {i}\!}{\text {Tr}_{1}^{m}}(1) = 0\) as m is even. Therefore, \(\phantom {\dot {i}\!}{\text {Tr}_{1}^{m}}(x^{r-1})={\text {Tr}_{1}^{m}}(1)=0\) for any \(\phantom {\dot {i}\!}x\in {\mathbb F}_{r}^{*}\) which further implies that \(\phantom {\dot {i}\!}{\mathbb F}_{r}^{*}\subset D\). According to the basic properties of finite fields, there exist two distinct elements \(\phantom {\dot {i}\!}x_{1}, x_{2} \in {\mathbb F}_{r}^{*}\) such that \(\phantom {\dot {i}\!}x_{1} + x_{2} \in {\mathbb F}_{r}^{*}\). Hence, {x 1,x 2,x 1 + x 2}⊂ D which means that the minimum distance of \(\phantom {\dot {i}\!}{\mathcal C}_{D}^{\bot }\) is 3.

When p is an odd prime, it is clear that − xD for any xD since r − 1 is even. Choose some x 1D and set x 2 = −x 1, then x 1x 2 and {x 1,x 2}⊂ D. This implies that the minimum distance of \(\phantom {\dot {i}\!}{\mathcal C}_{D}^{\bot }\) is 2. □

We remark that the linear code \(\phantom {\dot {i}\!}{\mathcal C}^{\bot }_{D}\) is bad when p > 2 since its minimum distance is only 2. However, it is at least almost optimal when p = 2 since any binary linear code with length n in (3) and dimension m has minimum distance at most 4 due to the sphere packing bound [13].

Example 4

Let p = 2 and k = 3. Then the binary code \(\phantom {\dot {i}\!}{\mathcal C}^{\bot }_{D}\) has parameters 49,43,3]. It is optimal due to [9].

Example 5

Let p = 2 and k = 4. Then the binary code \(\phantom {\dot {i}\!}{\mathcal C}^{\bot }_{D}\) has parameters 135,127,3]. It is optimal due to [9].

5 Concluding Remarks

In this paper, we studied a class of two-weight linear codes, and gave closed-form expressions of their length and weight distributions thanks to some known results on Kloosterman sums. The dual of the linear codes was proved to be optimal or almost optimal in the binary case. Finally, we mentioned that our linear code can be employed to construct secrete sharing schemes with nice access structures under the framework developed in [3].