{'fraction_non_alphanumeric': 0.042337884593920905, 'fraction_numerical': 0.013821198705308978, 'mean_word_length': 3.998047601338788, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Locally Decodable Codes with Randomized Encoding

We initiate a study of locally decodable codes with randomized encoding. Standard locally decodable codes are error correcting codes with a deterministic encoding function and a randomized decoding function, such that any desired message bit can be recovered with good probability by querying only a small number of positions in the corrupted codeword. This allows one to recover any message bit very efficiently in sub-linear or even logarithmic time. Besides this straightforward application, locally decodable codes have also found many other applications such as private information retrieval, secure multiparty computation, and average-case complexity. However, despite extensive research, the tradeoff between the rate of the code and the number of queries is somewhat disappointing. For example, the best known constructions still need super-polynomially long codeword length even with a logarithmic number of queries, and need a polynomial number of queries to achieve a constant rate. In this paper, we show that by using a randomized encoding, in several models we can achieve significantly better rate-query tradeoff. In addition, our codes work for both the standard Hamming errors, and the more general and harder edit errors.


Introduction
Locally decodable codes (LDCs) are error correcting codes that allow one to decode any specific message symbol by querying only a few symbols from the received codeword, while still tolerating some (say a constant) fraction of errors. This enables the appealing feature of recovering any message symbol very efficiently without reading the entire codeword, and usually this can be done in sublinear time. This feature is especially useful when dealing with large data streams (e.g., databases), and when the recovering of the entire data stream is unnecessary. While locally decodable codes can be defined over an alphabet of any size at least two, in this paper we focus on the case of binary alphabet. Standard locally decodable codes have been studied extensively for Hamming errors, and have found many applications in theory and practice. These include for example private information retrieval, secure multiparty computation, average-case complexity and many more. We refer the reader to [Yek12] for an excellent survey on this topic.
However, in contrast to standard error correcting codes which can achieve excellent rate (the ratio between the length of the message and the length of the codeword), for locally decodable codes the situation is somewhat disappointing. Specifically, if one considers the most natural and interesting case of tolerating a constant fraction of errors, then standard error correcting codes can simultaneously achieve a constant rate. For locally decodable codes, the rate also depends on the number of queries for decoding. Specifically, consider the standard setting where our goal is to recover any message bit with probability 2/3. With r queries and for message length k, it is known that the codeword length needs to be at least Ω(k (r/r−1) ) [KT00] and hence if r is a constant, 1 the codeword length needs to be at least polynomially long and thus achieving a constant rate is impossible. However, even for the case of r = O(log k) there is no explicit construction of locally decodable codes with constant rate, and in fact the best known construction in this case fails to achieve codeword length polynomially in k. Currently, the best known constructions need r = k Ω(1) queries to achieve a constant rate [KSY11]. Below we briefly summarize the parameters of the best known constructions for different regimes of query complexity, while fixing the success probability of decoding any bit to be say 2/3. For constant query r = O(1), the best known construction is by using matching vector codes [DGY11], which gives for example a code that uses r = 3 · 2 t−2 queries and can tolerate δ = O(1/r) fraction of errors. The codeword has length expexp t ((log k) 1/t (log log k) 1−1/t ), which is slightly subexponential. In contrast, the lower bound only gives a polynomial codeword length. For query complexity r = O(log k), the best known construction is also due to matching vector codes, which gives codeword length expexp(log log 3−o(1) k). Note that this is super-polynomial, while the lower bound already becomes useless. For query complexity r = log t k with constant t > 1, Reed-Muller codes give codeword length k 1+1/(t−1)+o (1) . Finally, for query complexity r = k ε for any constant ε > 0, multiplicity codes [KSY11] give codeword length O(k) while tolerating some constant δ = δ(ε) fraction of errors. Thus, there is a huge gap between the upper bounds and the lower bounds. This means that known constructions of locally decodable codes either need a lot of redundancy information, or need to use relatively large number of queries, which is undesirable. Closing this gap is an important open problem, which evidently appears to be quite hard.
Note that to ensure the property of local decoding, it is necessary to change the decoding from a deterministic algorithm into a randomized algorithm, since otherwise an adversary can just corrupt all the bits the decoding algorithm queries. Hence, the decoding becomes probabilistic and allows some small probability of failure. In this paper, with the goal of improving the rate of locally decodable codes in mind, we initialize the study of a relaxed version of locally decodable codes which is also equipped with randomized encoding. Now the probability of decoding failure is measured over the randomness of both the encoding and decoding.
There are several questions that we need to clarify in this new model. The first question is: Does the decoding algorithm know and use the randomness of the encoding? Although we cannot rule out the possibility of constructions where the decoding algorithm can succeed without knowing the randomness of the encoding, in this paper we only consider the most natural setting, where the decoding algorithm indeed knows and uses the randomness of encoding. After all, without the encoding's randomness the decoding algorithm does not even completely know the encoding function. The second question, as we are considering an adversarial situation, is: Is the adversary allowed to know the randomness of the encoding?
This turns out to be a very interesting question. Of course, an adversary who knows the randomness of encoding is much stronger, and thus we need a stronger construction of codes as well. In this paper, we provide a partial answer to this question, by showing that under some reasonable assumption of the code, a locally decodable code in our model where the adversary knows the randomness of encoding is equivalent (up to constant factors) to a standard locally decodable codes. The assumption is that the code has the following homogenous property: Property (*) : For any fixing of the encoding's randomness, any fixed error pattern, and any fixed target message bit, the success probability (over the decoding's randomness) of decoding this bit is the same for all possible messages.
We note that this property is satisfied by all known constructions of standard locally decodable codes. Part of the reason is that all known constructions are linear codes, and the decoding only uses non adaptive queries. We now have the following theorem. Theorem 1. Suppose there is an LDC with randomized encoding for Hamming errors, with message length k, codeword length n, that can tolerate δ fraction of errors and successfully decode any message bit with probability 1 − ε using r queries. Then there also exists a (possibly non explicit) standard LDC, with message length k/2, codeword length n, that can tolerate δ fraction of errors and successfully decode any message bit with probability 1 − 2ε using r queries.
Proof. Fix a specific random string used by the encoding, and a target message bit for decoding (say bit i). Since now the encoding becomes a deterministic function, and there are only finite number of possible error patterns, there is some error pattern that is the worst for decoding, i.e., the one that minimizes the success probability of decoding bit i. We say the fixed random string is good for bit i if this success probability is at least 1 − 2ε. Note that the overall success probability of decoding bit i is at least 1 − ε, thus by a Markov argument the probability that a random string is good for bit i is at least 1/2. Now again, by an averaging argument, there exists a fixed string that is good for at least 1/2 fraction of the message bits. Fix this string and the encoding now becomes deterministic. Without loss of generality assume that the string is good for the first half of the message bits. Now fix the rest of the message bits to any arbitrary string (e.g, all 0), we now have a standard LDC with message length k/2, codeword length n, that can tolerate δ fraction of errors and successfully decode any message bit with probability 1 − 2ε using r queries.
The above theorem shows that, in order to get significantly better rate-query tradeoff, we need to either forbid the adversary to know the randomness of encoding, or to construct codes that do not satisfy property (*) (e.g., using adaptive encoding or adaptive decoding). In this paper we study the first setting, which is naturally simpler, and we leave codes in the second setting as an interesting open problem. In general, there are two different models where the adversary is not allowed to know the randomness of encoding: Shared randomness In this model, the encoder and the decoder share a private uniform random string. Thus, the adversary does not know the randomness used by the encoder; but he can add arbitrary errors to the codeword, including looking at the codeword first and then adaptively add errors.
Oblivious channel In this model, the encoder and the decoder do not share any randomness. However, the communication channel is oblivious, in the sense that the adversary can add any error pattern non adaptively, i.e., without looking at the codeword first.
Here we study both models. We now give our formal definitions of locally decodable codes with randomized encoding.
Definition 1 (LDC with a fixed Failure Probability). An (n, k, δ, q, ε) LDC with randomized encoding consists of a pair of randomized functions {Enc, Dec}, such that: where the probability is taken over the randomness of both Enc and Dec.
• Dec makes at most q queries to y.
Remark. Two remarks are in order. First, our definition is quite general in the sense that we don't restrict the type of errors. In particular, in this paper we study both Hamming errors (i.e., bit flips) and edit errors (i.e., insertions, deletions, and substitutions). Second, as mentioned before, the model can either assume shared private randomness or an oblivious adversarial channel.
The above definition is for a fixed failure probability ε. However, sometimes it is desirable to achieve a smaller failure probability. For standard locally decodable codes, this can usually be done by repeating the decoding algorithm independently for several times, and then taking a majority vote. This decreases the failure probability at the price of increasing the query complexity. In contrast, in our new model, this approach is not always feasible. For example, in the extreme case one could have a situation where for some randomness used by the encoding, the decoding succeeds with probability 1; while for other randomness used by the encoding, the decoding succeeds with probability 0. In this case repeating the decoding algorithm won't change the failure probability. To rule out this situation, we also define a locally decodable codes with flexible failure probability.
• Dec : [k]×{0, 1} * → {0, 1} is the decoding function. If the adversary adds at most δn errors to the codeword, then for every i ∈ [k], every y ∈ {0, 1} * which is a corrupted codeword, and every ε ∈ [0, 1], while Dec makes at most q = q(n, ε) queries to y. The probability is taken over the randomness of both Enc and Dec.
Again, this definition can apply to both Hamming errors and edit errors, and both the model of shared randomness and the model of an oblivious adversarial channel.
To the best of our knowledge, locally decodable codes with randomized encoding have not been studied before in the literature. In this paper we provide several constructions with ratequery tradeoff better than standard locally decodable codes. We have the following theorems. The first one deals with a fixed decoding failure probability. Theorem 2. There exists a constant 0 < δ < 1 such that for every k ∈ N there is an efficient construction of (n, k, δ, q, ε) LDC with randomized encoding, where n = O(k). For any ε ∈ [0, 1], the query complexity is as follows.
• for Hamming errors with shared randomness, q = O(log 1 ε ); • for Hamming errors with an oblivious channel, q = O(log k log 1 ε ); • for Edit errors, both with shared randomness and with an oblivious channel, q = polylogk log 1 ε . We can compare our theorem to standard locally decodable codes. Achieving q = O(log 1 ε ) is equivalent to achieving constant query complexity for success probability 2/3. For standard LDCs we know in this case it is impossible to achieve a constant rate, and the best known construction still has sub-exponential codeword length. Similarly, achieving q = O(log k log 1 ε ) is equivalent to achieving query complexity O(log k) for success probability 2/3, and for standard LDCs the best known construction still has super-polynomial codeword length. In contrast, we can achieve a constant rate.
The next theorem deals with a flexible decoding failure probability. We note that one way to achieve this is to repeat the encoding several times independently, and send all the obtained codewords together. The decoding will then decode from each codeword and take a majority vote. However, this approach can decrease the rate of the code dramatically. For example, if one wishes to reduce the failure probability from a constant to 2 −Ω(k) , then one needs to repeat the encoding for Ω(k) times and the rate of the code decreases by a factor of 1/k. In this work we use a different construction that can achieve a much better rate.
Theorem 3. There exists a constant 0 < δ < 1 such that for every k ∈ N there is an efficient construction of (n, k, δ) LDC with randomized encoding and flexible failure probability, where n = O(k log k). The query complexity is as follows.
• for Hamming errors with shared randomness, q = O(log k log 1 ε ); • for Hamming errors with an oblivious channel, q = O(log 2 k log 1 ε ); • for Edit errors, both with shared randomness and with an oblivious channel, q = polylogk log 1 ε . We can also compare this theorem to standard locally decodable codes. Again, achieving q = O(log k log 1 ε ) is equivalent to achieving query complexity O(log k) for success probability 2/3, and for standard LDCs the best known construction still has super-polynomial codeword length. Similarly, achieving q = O(log 2 k log 1 ε ) is equivalent to achieving query complexity O(log 2 k) for success probability 2/3, and for standard LDCs the best known construction using Reed-Muller codes needs codeword length k 2+o (1) . In contrast, we can achieve codeword length O(k log k).

Related works.
As mentioned earlier, standard locally decodable codes for Hamming errors have been studied extensively, with many beautiful constructions such as [Yek08], [Efr09], [DGY11], and we refer the reader to [Yek12] for an excellent survey.
For edit errors, the situation is quite different. Even for standard error correcting codes (not locally decodable), the progress for edit errors is much slower than that for Hamming errors. For example, the first asymptotically good code for edit errors is not known until the work of Schulman and Zuckerman in 1999 [SZ99]. In recent years, there has been a line of research [GW17], [GL16], [BG16], [Bel15], [HSV18], [CJLW18], [Hae19], [CJLW19] that makes constant progress and finally culminates in [CJLW18], [Hae19] which give codes that can correct t edit errors with redundancy (the extra information needed for the codeword) size O(t log 2 (k/t)), where k is the message length. This is within a log(k/t) factor to optimal. In [CJLW18], the authors also give a code that can correct t edit errors with redundancy O(t log k), which is optimal up to constants for t ≤ k 1−α , any constant α > 0. In another line of work [HS17], [HS18], [CHL + 19], near optimal codes for edit errors over a larger alphabet are constructed, using the constructions of synchronization strings.
In terms of locally decodable codes, no known constructions for Hamming errors can be used directly as a code against edit error. This is due to the shift caused by insertions and deletions, which causes the loss of information about the positions of the bits queried. The only known previous work of locally decodable codes for edit errors is the work by Ostrovsky and Paskin-Cherniavsky [OPC15]. There the authors provided a "compiler" to transform a standard locally decodable code for Hamming error to a locally decodable code for edit error. Their construction first takes a standard LDC as a black box, then concatenate it with an asymptoticaly good code for edit errors. They showed that the fraction of error tolerated and the rate of the resulted code both only decrease by a constant factor. Meanwhile, the query complexity increases by factor of polylog(n), where n is the length of the codeword.
Standard error correcting codes with randomized encoding (but deterministic decoding) have been studied by Guruswami and Smith [GS16]. They constructed such codes for an oblivious adversarial channel that can add δ fraction of errors, where the rate of the codes approaches the Shannon capacity 1 − H(δ). Their encoding and decoding run in polynomial time and the decoding error is exponentially small.

Hamming Error
We start from constructions for Hamming errors and let the fraction of errors be some constant δ. To take advantage of a randomized encoding, our approach is to let the encoder perform a random permutation of the codeword. Assuming the adversary does not know the randomness of the encoding, this effectively reduces adversarial errors into random errors, in the following sense: if we look at any subset of coordinates of the codeword before the random permutation, then the expected fraction of errors in these coordinates after the random permutation is also δ. A stronger statement also follows from concentration bounds that with high probability this fraction is not far from δ, and in particular is also a constant. This immediately suggests the following encoding strategy: first partition the message into blocks, then encode each block with a standard asymptotically good code, and finally use a random permutation to permute all the bits in all resulted codewords. Now to decode any target bit, one just needs to query the bits in the corresponding codeword for the block that contains this bit. As the error fraction is only a constant, a concentration bound for random permutations shows that in order to achieve success probability 1 − ε, one needs block length O(log(1/ε)) and this is also the number of queries needed. To ensure that the adversary does not learn any information about the random permutation by looking at the codeword, we also use the shared randomness to add a mask to the codeword (i.e., we compute the XOR of the actual codeword with a random string). This gives our codes for a fixed failure probability, in the model of shared randomness.
To modify our construction to the model of an oblivious channel, note that here we don't need a random mask anymore, but the encoder has to tell the decoder the random permutation used. However the description of the random permutation itself can be quite long, and this defeats our purpose of local decoding. Instead, we use a pseudorandom permutation, namely an almost κ = Θ(log 1 ε ) wise independent permutation with error ε/3. Such a permutation can be generated by a short random seed with length r = O(κ log n + log(1/ε)), and thus is good enough for our application. The encoder will first run the encoding algorithm described previously to get a string y with length n/2, and then concatenate y with an encoded version z ∈ {0, 1} n/2 of the random seed. The decoder will first recover the seed and then perform local decoding as before. To ensure the seed itself can be recovered by using only local queries, we encode the seed by using a concatenation code where the outer code is a (n 1 , k 1 , d 1 ) Reed-Solomon code with alphabet size poly(n), and the inner code is an (n 2 , k 2 , d 2 ) asymptotically good code for O(log n) bits, where n 1 n 2 = n/2, k 1 k 2 = r, d 1 = n 1 − k 1 + 1, n 2 = O(log n). That is, each symbol of the outer code is encoded into another block of O(log n) bits. Now to recover the seed, the decoder first randomly chooses 8k 1 blocks of the concatenated codes and decodes the symbols of the outer code. These decoded symbols will form a new (shorter) Reed-Solomon code, because they are the evaluations of a degree k 1 polynomial on 8k 1 elements in F k2 2 . Furthermore, this code is still enough to recover the seed, because the seed is short and with high probability there are only a small constant fraction of errors in the decoded symbols. So the decoder can perform a decoding of the new Reed-Solomon code to recover the random seed with high probability. Note that the number of queries of this decoding is 8k 1 n 2 = O(r).
We now turn to our constructions for flexible failure probability. Here we want to achieve failure probability from a constant to say 2 −k . For each fixed failure probability we can use the previous construction, and this means the block size changes from a constant to O(k). Instead of going through all of these sizes, we can just choose O(log k) sizes and ensure that for any desired failure probability ε, there is a block size that is at most twice as large as the size we need. Specifically, the block sizes are 2 2 i , i = 1, 2, . . . , log k. In this way, we have O(log k) different codewords, and we combine them together to get the final codeword. Now for any failure probability ε, the decoder can look for the corresponding codeword (i.e., the one where the block size is the smallest size larger than 1/ε) and perform local decoding. However, we cannot simply concatenate these codewords together since otherwise δ fraction of errors can completely ruin some codeword. Instead, we put them up row by row into a matrix of O(log k) rows, and we encode each column of O(log k) bits with another asymptotically good binary code. Finally we concatenate all the resulted codewords together into our final codeword of length O(k log k).
Note that now to recover a bit for some codeword, we need to query a whole block of O(log k) bits, thus the query complexity increases by a log k factor while the rate decreases by a log k factor.

Edit Error
Our constructions for edit errors follow the same general strategy, but we need several modifications to deal with the loss of index information caused by insertions and deletions. Our construction for edit errors can achieve the same rate as those for Hamming case, but the query complexity for both models increases by a factor of polylogk. We now give more details. We start with the construction of an (n = O(k), k, δ = Ω(1), q = polylogk log(1/ε), ε) LDC for any ε ∈ (0, 1), in the model with shared randomness. As in the case of Hamming errors, the shared randomness is used in two places: a random permutation π and some random masks to hide information. The construction has two layers.
For the first layer, view the message x ∈ {0, 1} k as a sequence over the alphabet {0, 1} log k and divide it into k/(k 0 log k) small blocks each containing k 0 symbols from {0, 1} log k . Then, we encode each block with Enc 0 , which is an asymptotically good (n 0 , k 0 , d 0 ) code for Hamming errors over the alphabet {0, 1} log k . Concatenating these k/(k 0 log k) codewords gives us a string of length N = n0k k0 log k over the alphabet {0, 1} log k . We then permute these N symbols using π to get We are now ready to do the second layer of encoding. In the following, for each i ∈ [N ], b i ∈ {0, 1} log k is the binary representation of i and r i ∈ {0, 1} log k is a random mask shared between the encoder and decoder. C 0 : {0, 1} 2 log k → {0, 1} 10 log k is an asymptotically good code for edit errors and the ⊕ notation means bit-wise XOR. For each i ∈ [N ], we compute Note that the use of the random masks r i 's is to hide the actual codeword, so that the adversary cannot learn any information about the permutation.
To decode a given message bit, we need to find the corresponding block. The natural idea to do this is by binary search. However, this may fail with high probability due to the constant fraction of edit errors. To solve this issue, we use the techniques developed by [OPC15], which use a similar second layer encoding and give a searching algorithm with the following property: Even with δ-fraction of edit errors, at least 1 − O(δ) fraction of the blocks can be recovered correctly with probability at least 1 − neg(k). The algorithm makes a total of polylogk queries to the codeword for each search.
We now describe the decoding. Assume the bit we want to decode lies in the i-th block of x. Let C i ∈ ({0, 1} log k ) n0 be the codeword we get from encoding the i-th block using Enc 0 . With the information of π, we can find out n 0 indices . The decoding algorithm calls the searching algorithm from [OPC15] to find all blocks B ′ i1 to B ′ in 0 in the received codeword. We say a block is unrecoverable if the searching algorithm failed to find it correctly. By the same concentration bound used in the Hamming case and the result from [OPC15], the fraction of unrecoverable blocks is bounded by a small constant with high probability. Thus, we can decode C i correctly with the desired success probability. In this process, each search takes polylogk queries and n 0 = O(log 1/ε) of searches are performed. The total number of queries made is thus polylogk log 1/ε.
For the model of an oblivious channel, again we use a pseudorandom permutation π that can be generated by O(log n log 1/ε) random bits. We use the same binary code as we used in the Hamming case to encode it and then view it as a string over the alphabet {0, 1} log k . It is then concatenated with the code described previously before the second layer of encoding. After that, the same second layer of encoding is applied. The random masks used in the previous construction are no longer needed since the adversary can not see the codeword.
The construction for a flexible failure probability is also similar to the Hamming case. We write the codes before the second layer of encoding as a matrix M . The only difference is that, each element in the matrix M is now a symbol in {0, 1} log k . We then encode the j-th column with an error correcting code over the alphabet {0, 1} log k to get a codeword z j , and concatenate them to get z. After that, we do the second layer of encoding on z.

Edit distance
Edit distance, or Levenstein distance, is a popular metric for quantifying how similar two strings are. It is defined using three types of string operations: insertion, deletion, and substitution. An insertion operation inserts a character into the string at a certain position. A deletion operation deletes a particular character from the string. And a substitution operation substitutes a character with a different one.
Definition 3. The edit distance between two strings x, y ∈ Σ * , denoted by d E (x, y), is the minimal number of edit operations (insertion, deletion, and substitution) needed to transform one into another. Assume x and y have same length n, the normalized edit distance of x and y is d E (x, y) devided by n. We denote the normalized edit distance by ∆ E (x, y)

Pseudorandom permutation
In our construction against oblivious channel, one key idea is to integrate a short description of a pseudorandom permutation into the codeword. We will utilize the construction of pseudorandom permutations from [KNR09]. Here, we follow the definition from their work and introduce their results.
Definition 4 (Statistical Distance). Let D 1 , D 2 be distributions over a finite set Ω. The variation distance between D 1 and D 2 is Definition 5 (k-wise δ-dependent permutation). Let F be a family of permutations on n elements (allow repetition). Let δ > 0, we say the family F is k-wise δ-dependent if for every k-tuple of distinct elements {x 1 , x 2 , · · · , x k } ∈ [n], for f ∈ F chosen uniformly, the distribution In practice, we want to construction explicit families of permutations. Two related parameters are: Definition 6 (Description length). The description length of a permutation family F is the number of random bits, used by the algorithm for sampling permutations uniformly at random from F .
Definition 7 (Time complexity). The time complexity of a permutation family F is the running time of the algorithm for evaluating permutation from F It is known that we can construct families of k-wise almost independent permutations with short description length (optimal up to a constant factor).
Theorem 4 (Theorem 5.9 of [KNR09]). Let P n denote the set of all permutation over {0, 1} n . There exists a k-wise δ-dependent family of permutation F ⊂ P n . F has description length O(kn + log 1 δ ) and time complexity poly(n, k, log 1 δ ).

With a Certain Failure Probability
We first show the construction of a Random Encoding LDC with an arbitrarily fixed failure probability for the case of shared randomness.
We claim that the random permutation π and the z are independent. Actually for arbitrary permutation σ and arbitrary n-bit string a, Because conditioned on any fixed permutation, to let z = a, there is a unique choice of w.
On the other hand, Pr[π = σ] = 1 n! and Pr[z = a] = 2 −n . This shows the independence of π and z.
So even if the adversary operates based on knowing z, the set of positions of the tampered bits are independent of π.
Since the number of errors is at most δn, the expected number of corrupted bits in y ′ i ′ is at most δn 0 . By Lemma 1, the probability that the number of corrupted bits in y ′ i ′ is at most 1.1δn 0 , is at least 1 − 2 −0.01n0/3 ≥ 1 − ε/2. By choosing n 0 to be large enough. Let delta 0 = 1.1δ. Then Dec 0 can recover the desired bit from y ′ i ′ which has at most 1.1δn 0 errors. Note that the construction runs in polynomial time because generating random permutation, permuting bits, (Enc 0 , Dec 0 ) are all in polynomial time. The number of queries is n 0 = O(log 1 ε ), since we only query bits in y ′ i ′ . Next we give the construction for oblivious channels. We use the almost t-wise independent random permutations instead of random permutations for this case. A random function π : [n] → [n] is an ε almost t-wise independent random permutation if for every t elements i 1 , . . . , i t ∈ [n], (π(i 1 ), . . . , π(i t )) has statistical distance at most ε from (π ′ (i 1 ), . . . , π ′ (i t )) where π ′ is a random permutation over [n]. Kaplan, Naor and Reingold [KNR09] gives an explicit construction.
Before the main construction, we first show a binary "locally decodable code" which can recover the whole message locally when the message length is sufficiently small.

Lemma 2.
For every k ≤ cn with sufficiently small constant c = c(δ) < 1, every sufficiently small constant δ, there is an explicit (n, k, δn) binary ECC, which has a randomized decoding algorithm s.t. it can compute the message with success probability 1 − 2 −Θ(k/ log n) , querying at most q = O(k) bits.
Proof. Consider the concatenation of an (n 1 , k 1 , d 1 ) Reed-Solomon code with alphabet {0, 1} n2=O(log n1) , n 1 = n/n 2 , k 1 = k/k 2 , and an explicit (n 2 , k 2 = n 2 − 2d 2 (log n2 d2 ), d 2 = Θ(n)) binary ECC. The concatenated code is an (n 1 n 2 , k 1 k 2 , d 1 d 2 ) code. Note that n 1 n 2 = n, k 1 k 2 = k. Also We only need to show the decoding algorithm. Given a codeword, we call the encoded symbols (encoded by the second code) of the first code as blocks. The algorithm randomly picks 8k 1 blocks and query them. For each block, it calls the decoding function of the second code. After this we get 8k 1 symbols of the first code. Then we use the decoding algorithm of a (8k 1 , k 1 , 7k 1 + 1) Reed Solomon code to get the message.
Next we argue that this algorithm successes with high probability. Assume there are δn = d 1 d 2 /8 errors, then there are at most d 1 /4 codewords of the second code which are corrupted for at least d 2 /2 bits. Since the distance of the second code is d 2 , there are n 1 − d 1 /4 blocks can be decoded to their correct messages.
Hence the expectation of the number of correctly recovered symbols of the first code is n1−d1/4 n1 8k 1 ≥ 6k 1 . Thus by Chernoff Bound, with probability 1 − 2 −Θ(k1) , there are at least 5k 1 symbols are correctly recovered. Note that if we look at the 8k 1 queried blocks they also form a (8k 1 , k 1 , 7k 1 + 1) Reed-Solomon code since it is the evaluation of the degree k 1 − 1 polynomial on 8k 1 distinct values in the field F n2 2 . Thus, our recovered symbols form a string which has only distance 3k 1 from a codeword of the code. So by using the decoding algorithm of the code we can get the correct message.
1. On the input i and y • z, call the decoding algorithm from Lemma 2 on z to get r; 2. Use r to reconstruct π; Lemma 4. The number of queries for the decoding algorithm is q = O(log n log 1 ε ). Proof. In step 1 of the decoding, calling the decoding algorithm from Lemma 2 takes O(d π ) number of queries.
In step 4 of the decoding, the number of queries is n 0 . So the total number of queries is n 0 + O(d π ) = O(log n log 1 ε ).
Lemma 5. Assume there are δn errors, then with probability 1 − ε, the decoding can get x correctly.
Proof. For z, the number of errors is at most δn. Thus by Lemma 2, the decoding can get r correctly with probability 1 − ε/3 by letting the constant factor in |r| = d π to be large enough. For y, the number of errors is at most δn. If π is a uniform random permutation then the expected number of corrupted bits in y ′ i ′ is 2δn 0 . By Lemma 1, the probability that the number of corrupted bits in y ′ i ′ is at most 2.2δn 0 is at least 1 − 2 −0.01δn0/3 ≥ 1 − ε/3 if letting the constant factor in n 0 to be large enough.
Note that once x i ′ is recovered, x[i] is in it and thus is correctly recovered.

With Flexible Failure Probabilities
Next we consider a stronger definition which can handle all decoding failure probabilities.
Intuitively we want to use the previous construction for different eps, and then combine them. It turns out this indeed can work but with some extra techniques while the information rate is Θ(1/ log n).

Let
2. Compute w = Dec i (u, y i ) but whenever Dec i wants to query an j-th bit of y i , we query z j and get y i [j] from Dec 0 (z j ); 3. Output w.
Lemma 6. The encoding and decoding are both efficient.
Proof. Every step in the construction can be realized in polynomial time. The called functions in the construction are all from efficient constructions.
Lemma 7. The number of queries for the decoding algorithm is q = O(log 2 n log 1 ε ). Proof. In step 2 of the decoding, calling the decoding algorithm from Theorem 6 takes O(log n log 1 ε ) number of queries. For each such query, the algorithm actually queries n 0 bits. So the total number of queries is as stated.
Proof. As δ = δ 0 min j {δ j }, there are at most δ j n 1 number of z j s which each has more than δ 0 fraction of errors.
As a result, for y j , there are at most δ j n 1 number of bits which cannot be computed correctly during decoding step 2. So Dec j can compute x[i] correctly by Theorem 6.
Similarly we also have the following result for the case of shared randomness Theorem 8. There is an efficient construction of (n, k = Ω(n/ log n), δ = Θ(1)) random LDC which can recover any one message bit with probability 1 − ε, for any ε ∈ [0, 1], by doing q = O(log 2 n log 1 ε ) queries. Proof Sketch. We modify Construction 3 by letting (Enc i , Dec i ), i ∈ [log n] be from Theorem 5.
Note that the outputted codeword is independent of the permutations used in (Enc i , Dec i ), i ∈ [log n] due to the using of masks in the construction of Theorem 5. This guarantees that a similar analysis can still work for this case.

Constructions against Edit Error
The constructions against edit error requires an additional layer of encoding. To make our proof easier to describe, we will utilize the following greedily constructed code from [SZ99].
Lemma 9 (Implicit from [SZ99]). For small enough δ, there exists code C : {0, 1} n → {0, 1} 4n such that the edit distance between any two codewords is at least δ and for any codeword, every interval has at least half of 1's.
The proof uses the same argument from [SZ99]. The only difference is that their proof only considers insertion and deletion. Our slightly modified proof includes substitution as a type of error.
Proof. For a codeword y, the number of words in {0, 1} n that is within edit distance 2d is at most n 2d 2 2 2d . That is because each substitution can be replaced by a deletion and an insertion.
For any two codewords x and y such that d E (x, y) ≤ d, x can be transformed into y with at most 2d insertions and 2d deletions. There are n 2d ways to delete 2d characters from y, n n−2d ways to put the remaining characters in proper position of x, and 2 2d ways to choose to the inserted characters.
Substitute d with δn for some small constant δ, since n k ≤ ( ne k ) k , we have n 2δn Pick δ ∈ (0, 0.018), we have n 2δn 2 2 2δn ≤ 2 1/2n . This gives a greedy construction of edit error code with rate 1 2 and tolerates a δ fraction of edit error for constant δ ≤ 0.018. We then ensure every interval has at least half 1's by inserting 1's into every other position. Note that this operation will not decrease the edit distance. It gives us a code with rate 1/4.
In the discussion below, we will use the following error correcting code for edit distance: such that for each message S ∈ {0, 1} N , C 0 (S) is composed of two parts. The first part is a codeword 4N is a greedily constructed code that can tolerate a constant fraction of edit errors. The second part is a buffer of 0's of length N . That is, C 0 (S) = C ′ 0 (S) • 0 N . We assume the normalized edit distance between any two codewords of C 0 (S) is at least δ ′ .
Another key component in our construction against edit error is a searching algorithm developed by [OPC15].
Their work provides an algorithm for searching from a weighted sorted list L with a constant fraction of errors. An element (i, a i ) in the sorted list is composed of two parts, an index i and content in that element, a i . All elements in the list are sorted by their index, i.e. the j-th element in L is (j, a j ). Beyond that, each element is equipped with a non-negative weight. When sampling from the list, each element is sampled with probability proportional to its weight.
In [OPC15], the authors proved the following result.
[Theorem 16 of [OPC15]] Assume L ′ is a corrupted version of a weighted sorted list L with k elements, such that the total weight fraction of corrupted elements is some constant δ of the total weight of L. And the weights have the property that all sequences for r ≥ 3 elements in the list have total weight in the range [r/2, 2r]. Then, there is an algorithm for searching L. This lemma enables us to search from a weighted sorted list (with corruption) with few (polylogk) queries. To make our proof self-contained, we will describe how to turn the encoded message in our construction into a weighted sorted list in the proof.
We are now ready to describe our construction.
Let C 0 : {0, 1} 2 log k → {0, 1} 10 log k be the asymptotically good code for edit error described previously that can tolerate a δ ′ fraction of edit error.
Proof. We first show both the encoding and decoding can be done in polynomial time. Although for the ease of description, we picked the greedily constructed code C 0 , which can be inefficient. The codeword size of C 0 is O(log k). Decoding one block can be finished in time polynomial in k. And for our purpose, we need to encode O(k/ log k) blocks and decode polylogn log 1 ε blocks. Thus, the additional time caused by this layer of encoding is polynomial in n. For the rest part, the analysis is similar to that of the Hamming case. Thus, our code is polynomial time. We note that C 0 can be replaced by an efficient code for edit error. We use the same notation as in our construction. Let y = B (3) N be the correct codeword. We denote the length of each block B (3) j by b = 10 log k and if we view y as a binary string, the length of y is N ′ (= N b), which is O(k). We call the received (possibly corrupted) codeword ω. Since we can always truncate (or pad with 0) to make the length of ω be N ′ , which will only increase the edit distance by a factor no more than 2. Without loss of generality, we assume the length of ω is also N ′ .
The decoding function Dec has two inputs: an index i 0 ∈ [k] of the message bit the decoder wants to see and the received codeword ω. The decoder also has access to the shared randomness, which has two parts: a permutation π and N random masks, each of length log k. The first step is to figure out the indices of the blocks it wants to query by using the shared permutation π. Then, we can query these blocks one by one. We assume the i 0 -th bit lies in B in0 . Our goal is to find the block B (3) π(j) for each j ∈ {(i − 1)n 0 + 1, (i − 1)n 0 + 2, . . . , in 0 }.
One thing we need to clarify is how to query a block since we do not know the starting point of each block in the corrupted codeword. This is where we use the techniques developed by [OPC15]. In the following, assume we want to find the block B (3) i . We can view y as a weighted sorted list L of length N such that the i-th element in L is simply B (3) i with weight b. We show that ω can be viewed as a corrupted list L ′ . There is a match from y to ω which can be described by a function f : If the i-th bit is preserved after the edit error, then f (i) = j where j is the position of that particular bit in ω. If the i-th bit is deleted, then f (i) =⊥.
We say the i-th bit in y is preserved after the corruption if f (i) =⊥. For each block B (3) i that is not completely deleted, let v i = f (u i ), such that u i is the index of the first preserved bit in the block B (3) i . We say the block B Proof. The code C 0 is greedily constructed and resilient to δ ′ fraction of error. Here, δ is picked smaller than δ ′ . To make an block corrupted, the adversary needs to produce at least a δ ′ fraction of edit error in that block. The adversary channel can corrupt at most δ δ ′ fraction of all blocks.
The searching algorithm requires sampling some elements from the sorted list L ′ corresponding to the corrupted codeword ω. We now explain how to do the sampling. We start by first randomly sample a position r and read a substring of 2r + 1 bits ω [r−b,r+b] from ω. Then, we try each substring in ω [r−b,r+b] of length b from left to right until we find first substring that is δ 0 -close to some codeword of C under the normalized edit distance. If we did find such a substring, we decode it and get b j • B (2) j ⊕ r j . Otherwise, output a special symbol ⊥. We will regard consecutive intervals in ω as elements in the weighted sorted list where weight of the element is simply the length of the corresponding interval. The correspondence can be described as following.
For a recoverable block B (3) i , again, we let v i = f (u i ), such that u i is the index of the first preserved character in block B (3) i . We want to find an interval I i in ω to represent B can not be δ ′ close to any codeword in C 0 . It is because the last 1/5 part of ω [v,v+b−1] contains , such that, if sampling r in I i , it will output same codeword in C. Also, we argue the length of the inteval I i is no larger than (3) i and thus output a different codeword. We note due to the existence of adversary insertion, it is possible to get B (3) i outside of I i . But this does not affect our analysis below.
The above method for sampling a block from ω gives us a natural way to interpret ω as a corrupted weighted list L ′ . The length of ω is equal to the sum of weights of all its elements. For each recoverable block, the interval I i as described above is an element with weight equal to its length. We note that all I i 's are disjoint. We consider the remaining characters in ω as corrupted elements in the list L. For those elements, the sampling algorithm will output wrong result or ⊥. Since the interval of the remaining elements can be large, we divide such interval into small intervals each has length no larger than b and consider each small intervals as an element.
Next, we argue the weight fraction of corrupted elements is small. Due to claim 1, there are at least a 1−δ/δ ′ fraction of blocks recoverable after the corruption. For each recoverable block B (3) i , we can find a interval I i in ω with length at least (1−2δ 0 )b. Thus, the total weight of uncorrupted elements from the original list L is at least ( , we know the total weight of corrupted elements is at most δ 1 fraction of the total weight of list L ′ . We assume δ 1 is small by properly picking δ and δ ′ . By lemma 10, 1 − δ 2 fraction of elements can be decoded correctly with high probability (1 − neg(n)) for some constant δ 2 = O(δ). Since the content of each block is protected by random masks. The adversary can learn nothing about the random permutation π used for encoding. Each block is recoverable with same probability. We want to search from y to find all blocks B (3) π(j) for each j ∈ {(i − 1)n 0 + 1, (i − 1)n 0 + 2, . . . , in 0 } to get a possibly corrupted version of Enc 0 (B (0) i ). The proof of success probability follows the same concentration bound as in the Hamming case. Here, the random masks serve the same purpose as in the Hamming case. The content of each block (not the index) is not known to the adversary. Thus, the adversary can learn nothing about the permutation or the message. By picking properly the code (Enc 0 , Dec 0 ), using the concentration bound, the fraction of unrecoverable blocks among these n 0 blocks is larger than 1 − 1.1δ 2 with probability at least 1 − ε.
Finally, we count the number of queries made. Searching one block queries polylogk symbols from the corrupted codeword ω. We need to search n 0 = O(log 1 ε ) blocks. The total number of queries made is polylogk log 1 ε .

Oblivious Channel
Now, we consider the oblivious channel. In this model, we assume the adversary can not read the codeword. Same as the Hamming case, we want to send a description of a permutation to the decoder. The decoder can then use description to recover the permutation π which is used to encode the message. We can use the same binary error correcting code from Lemma 2 to encode the description. We now give the construction.
Let C 0 : {0, 1} 2 log k → {0, 1} 10 log k be the asymptotically good code for edit error as described above that can tolerate a δ ′ fraction of edit error.
The encoding function Enc : {0, 1} k → {0, 1} n is a random function as follows: 1. Encode the message x with Construction 4 without doing steps 4,5, and 6. This does not require knowing permutation π. View the sequence we get as a binary string. View the output as a binary string y with length n/10; 2. Let N 1 = n 20 log k . Generate a random seed r ∈ {0, 1} d of lengh d. Here, d = O(κ log N 1 + log(1/ε π )) = O(log n log 1 ε ). Use r to sample a ε π = ε/10-almost κ = O(log 1 ε )-wise independent random permutation π : [N 1 ] → [N 1 ] using Theorem 4; 3. Let δ 1 be a properly chosen constant larger than δ. Encoding r with an (n/20, d, δ 1 n) error correcting code from Lemma 2, we get z ∈ {0, 1} n/10 ; 4. View y • z as a sequence in {0, 1} n/10 . Divide y • z ∈ {0, 1} n/10 into small blocks of size log k. Write y • z as y • z = B 1 • B 2 • · · · • B n/(10 log k) ; 5. Permute first half of blocks with random permutation π to get u ′ = B (1) n/(10 log k) such that B  1. Search for at most O(log n log 1 ε ) blocks to decode the random seed r; 2. Use r to generate the random permutation π; 3. Run the same decoding algorithm as in the Construction 4 on the first half of ω to decode x i0 .
Proof. The proof of efficiency of this construction follows directly from the proof of Lemma 11.
The first step is to decode r. By Lemma 2, we need to query O(d) bits of z to decode r with high probability 1 − neg(k). Thus, we need to query O(log k log 1 ε ) blocks in the second half of ω. We can then use the same searching algorithm described in the proof of Lemma 11 to query each block. Since we randomly choose blocks to query, we can recover r with probability 1 − neg(k) by making polylogk log 1 ε queries to ω 2 . Once we know r, we can use it to generate the random permutation π. We run the decoding algorithm from Construction 4 with input i 0 and ω 1 . The remaining part is the same as the proof of Lemma 11. Notice that recovering r takes polylogk log 1 ε queries. The query complexity for our code is still polylogk log 1 ε .

Shared Randomness
We now give the construction for flexible failure peobability against edit error.
Construction 6. We construct an (n, k = Θ(n/ log n), δ = O(1)) randomized LDC with query complexity function q = polylogk log 1 ε for any given failure probability ε. Let π be a random permutation. And r i ∈ {0, 1} log k for each i ∈ n/(10 log k) be random masks. Both π and r i 's are shared between the encoder and decoder.
For each i ∈ [log n], let Enc i be the encoding algorithm of an (n i , k, δ i = O(1), q i , ε = 2 −2 i ) randomized LDC from Construction 4 without steps 4,5, and 6. Let Dec i be the correponding decoding algotithm.
Let C 1 : {0, 1} 3 log k → {0, 1} 15 log k be the asymptotically good code for edit error as described above that can tolerate a δ ′ fraction of edit error.
1. On input x ∈ {0, 1} k , compute y i = Enc i (x) for every i ∈ [log n]. As before, we view Decoding function Dec is a randomized algorithm takes three inputs: an index of the bit the decoder wants to see,the received codeword ω, and the desired failure probability ε. It can be described as follows.
Lemma 13. The above construcion 6 gives an efficient (n, k = Θ(n/ log n), δ = O(1)) randomized LDC that can recover any bit with probability at least 1 − ε for any constant ε ∈ (0, 1), with query complexity q = polylogk log 1 ε . Proof. In the encoding, we need to encode n 0 N = O(n/ log n) blocks with edit error code C 0 . And in the decoding, we need decode at most polylogn log 1 ε blocks. The time caused by the second layer is polynomial in n. Thus, our construction is efficient.
After a δ fraction of edit error. There is some constant δ 1 = O(δ) such tath for at least 1 − δ 1 fraction of blocks, we can use the searching algorithm to find and decode them correctly with probability 1 − neg(n). Thus, as is described in the construction, when ever we want to query the j-th symbol of y i , we fist decode z j . The symbols of z j is encoded in n 0 blocks in ω. With π, we know the indices of these n 0 blocks. We can than perform the search as described in the proof of Lemma 11. By picking proper n 0 , the decoding of z j fails with a small probability. The rest of analysis follows directly from the proof of Lemma 11.
For the query complexity, we need to query O(n 0 log 1 ε ) blocks. Since n 0 = O(log n) = O(log k), the total number of queries made is still polylogk log 1 ε .

Oblivious Channel
Our construction for flexible failure probability against oblivious channel combines Construction 5 and Construction 6. More specifically, following the Construction 6, we replace the encoding functions Enc i for each i ∈ [log n] from Construction 4 with the encoding functions from Constructon 5. The analysis follows directly. We omit the details.

Discussions and open problems
In this work we initiated a study of locally decodable codes with randomized encoding, and we give constructions for both Hamming errors and edit errors, that significantly improve the rate-query tradeoff of known constructions. Our work leaves many interesting open problems. We list some below.
Question 1: Are there constructions of locally decodable codes with randomized encoding, such that the decoding can succeed without known the randomness of encoding? If so how do such codes perform?
Question 2: If the adversary is allowed to know the randomness used by the encoding, is it still possible to achieve much better rate-query tradeoff by using locally decodable codes with randomized encoding?
Question 3: Is it possible to construct locally decodable codes with a constant rate, while achieving flexible failure probability, by using randomized encoding?
Question 4: Can we further improve the number of queries in our constructions for an oblivious channel?
Finally, even standard locally decodable codes for edit errors are still are poorly understood. For example, for a constant fraction of error and constant alphabet size, the best approach is still due to [OPC15] which needs at least polylog(k) queries. Can we prove a lower bound for query complexity in this case, or is there an LDC construction with constant number of queries?