Baby_Step, Gaint_Step (analysis details + template), babystep transliteration lyrics

Source: Internet
Author: User

Baby_Step, Gaint_Step (analysis details + template), babystep transliteration lyrics

The following is a summary of other people's blog materials and their own learning experience.


[Baby_Step, Gaint_Step definition]

The high-order homogeneous equation. BL = N (mod P)

Solve the smallest L. Because of the large data range, brute force is ineffective.

The baby_step and giant_step algorithms are used here. This is a small step.

So that L = I * m + j (m = ceil (sqrt (p-1 ))),

Then the original format is B ^ (I * m) * B ^ j = N (mod p) ---- "B ^ j = N * B ^ (-I * m) (mod p)

We first pre-process B ^ 0, B ^ 1, B ^ 2 ...... B ^ m-1), which is saved to the HASH table ., This step is the baby-step, moving 1 at a time

Then, obtain B ^-m and enumeration I. If B ^ (-I * m) exists in the HASH table, the solution L = I * m + j exists, this step is giant_step.

For the method of B ^ (-m), you can first find the reverse element of B, that is, B ^-1.

Note that the above solution is the most basic and can only be used for gcd (B, P) = 1


[Disintegration ideas]

We can make an equivalent
X = I * m + j (0 <= I <m, 0 <= j <m) m = Ceil (sqrt (C ))
The purpose of such decomposition is nothing more than to convert:
(A ^ I) ^ m * A ^ j = B (mod C)

Then you can solve the problem by doing a little violent work:
(1) for I = 0-> m, insert Hash (I, A ^ I mod C)
(2) Enumeration I. For each enumerated I, make AA = (A ^ m) ^ I mod C
We have
AA * A ^ j = B (mod C)
Obviously, AA, B, and C are all known. Because C is a prime number(AA, C) 1 unconditionally
Therefore, the number of solutions to this model equation is unique (it can be solved by extending Euclidean or Euler's theorem)
For the obtained unique solution X, search in the Hash table. If it is found, the return value isI * m + j
Note:Due to the small to large enumeration of I, the j in the Hash table must be the smallest element X in a residual system (that is, the indicator)
Therefore, we can obtain the explain solution at this time.


If you want to obtain a solution of x> 0, you only need to judge in the preceding step that the return value is when I * m + j> 0.

So far, the above algorithms are not controversial, and the Code implemented by everyone is not much different. It can be seen that when C is a prime number, the problem of such discrete logarithm can become very easy to implement.


[TEMPLATE]

Poj 2417

/* NYIST_ZSJ [Normal edition] Baby_Step, in the form of Gaint_Step: A ^ x = B (mod C) usage conditions: 1. Large data range, in the case of no brute force, 2. C must be a prime number and return the result: if there is a solution, the partial solution must be returned. * /// Fast power a ^ B // a ^ B % nLL pow_mod (LL a, LL B, LL n) {LL res = 1; while (B) {if (B & 1) res = (res * a) % n; a = (a * a) % n; B = B> 1;} return res ;} // solve the modulo equation a ^ x = B (mod n), where n is a prime number and no solution returns-1 // ferma's small Theorem a ^ (n-1) = 1 (mod n ), n is a prime number. a ^ 0 = 1, so the cyclic section is less than or equal to n, that is, if there is a solution, then x <= n // a ^ x = B (mod n) ll bsgs (LL a, LL B, LL n) {LL m, v, e = 1; m = ceil (sqrt (n + 0.5 )); // x = I * m + j // v = inv (pow_mod (a, m, n), n) // a ^ m * v = 1 (mod n) v = pow_mod (a, n-m-1, n); // v = A ^-m map <LL, LL> x; x [1] = m; for (int I = 1; I <m; ++ I) {// first step (Baby_Step), create a hash table, and save x ^ 0, x ^ 1 ,..... x ^ M-1 = (e * a) % n; if (! X [e]) x [e] = I;} for (int I = 0; I <m; ++ I) {// Add (Gaint_Step) to the power of each m ), traverse all 1 <= x <= n if (x [B]) {LL num = x [B]; x. clear (); // clear return I * m + (num = m? 0: num);} // judge a ^ j =? B * a ^ (-m * I) % n, whether it exists in the hash table. If there is a ^ (I * m + j) = B (mod c) set B = (B * v) % n; // B = B/(a ^ m)} return-1; // no solution}


[Summary]

The total time complexity of the above algorithm is close to O (sqrt (C) * log (C) (C is a model)


References: templates, ACM_cxlove, and AekdyCoin]


Zookeeper
What does baby step mean?

The intention is: (BABY) toddler, toddler
It can be extended to do something for the first time, for example: Just take a baby step! Let's try it!
Doing anything for the first time is just like a baby step, so don't be so frightened!
Reference: I sincerely wish you a happy...

How to analyze webpage templates

ASP Web Page Template application: separates the program from the interface, makes ASP scripts clearer, and replaces the interface to avoid maintenance difficulties caused by mixed ASP and HTML code writing, this article introduces a method to use templates to separate programs and pages, making program design easier. When using ASP to create a site, a combination of program code and HTML code often occurs in an ASP file. This method has many disadvantages: 1. not to mention the design and arrangement of the page layout when programming, resulting in code confusion, difficulty, and non-standardization; 2. when you need to change the page appearance, you not only need to change the HTML part, but also need to change the ASP code, which is not easy to maintain. So how can we avoid these troubles? The answer is to use a template file to separate ASP code from HTML pages. All problems are solved. Using web templates has the following benefits: 1. the appearance of the entire site can be replaced in a short time; 2. this allows programmers to abstract programming without having to access HTML code. 3. you can reuse the previous template. PHP has a template program (FastTemplate), and the question is how to implement similar functions in ASP. Microsoft ASP has two types of scripts: VBScript and JScript. They all contain a "RegExp object" (RegExp). Using string objects and RegExp objects, you can easily implement the template function. Mu Feng wrote a "Template. JScript. INC" file. The content of this file is attached to the end of the article. Competent readers can make improvements based on their own needs. The following describes how to use it. Because this file is written in JScript (of course, it is easy to convert it to VBScript), the default script language should be set to JScript, that is, the first line of the ASP program should be: <% @ Language = JScript %>, and then include the template program file: <! -- # Include file = "Template. JScript. INC" -->. First, we will introduce the usage of the Template class: 1. Create the storage Path of the Template object: Template (Path) parameter: Path (string type) HTML Template file. Use the new operator to create a Template object. Example: var tpl = new Template ("c: \ template"); you can use tpl in the program. tplPath to obtain the template path. You can also use tpl. tplPath to change the template path. For example, tpl. tplPath = "d: \ template"; 2. load Template file: Template. load (Name, File) parameter: Name (string type) is a template variable Name. File (string type) template File name. This file is stored in the HTML template path. Read the File to the template variable Name. Example: tpl. Load ("Main", "TEST. HTM"). In this case, the template variable Main contains the content of the file TEST. HTM. You can use tpl. Main to access the template variable "Main ". Example: <% = tpl. Main %> the content of the TEST. HTM file that you just read is displayed. 3. Template Split: Template. Split (Name) parameter: Name (string type) is a Template variable Name. Break down sub-templates in Name. Example: assume that the content of TEST. HTM in the above example is: ----------------- this is the main template. Next: <! -- # Tpldef sub -- & g ...... remaining full text>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.