Sequence generation method and apparatus, electronic device, and computer-readable storage medium
By generating intermediate variables and rearranging the initial random sequence, the problem of insufficient randomness in the existing technology is solved, achieving higher security and efficiency.
Patent Information
- Application Number
- CN202210556722.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-20
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2042-05-20
AI Technical Summary
Existing random permutation algorithms generate random sequences with insufficient randomness, resulting in low security of the generated random passwords and random accounts, making them easy to crack.
By generating intermediate variables, an initial random sequence is generated and rearranged, including translation, OR, and modulo operations. Finally, the initial random sequence is divided into multiple subsequences and rearranged in parallel to improve the randomness and security of the sequence.
It improves the randomness and security of the generated random sequences, reduces memory requirements, and improves rearrangement efficiency.
Smart Images

Figure CN114968178B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and more specifically, to a sequence generation method, apparatus, electronic device, and computer-readable storage medium. Background Technology
[0002] Random permutation algorithms are algorithms used to generate random sequences, and they can be applied in various scenarios. For example, they can be used to generate random passwords, random account names, etc.
[0003] However, current random permutation algorithms have very limited random permutations and generate insufficient randomness in random sequences, resulting in a limited number of random passwords and random accounts that can be generated. The number of random passwords or random accounts generated based on random permutation algorithms is also relatively limited, which makes random accounts or random passwords easier to crack. Therefore, random accounts or random passwords have security issues. Summary of the Invention
[0004] The purpose of this application is to provide a sequence generation method, apparatus, electronic device, and computer-readable storage medium to improve the problem of insufficient randomness in generated random sequences.
[0005] In a first aspect, the present invention provides a sequence generation method, comprising: generating an intermediate variable according to a specified number; generating an nth element of an initial random sequence according to the intermediate variable, wherein n is a positive integer greater than or equal to 1 and less than or equal to a specified number; and rearranging the specified number of elements in the initial random sequence to obtain a target random sequence.
[0006] In an optional implementation, generating intermediate variables based on the specified quantity includes: determining intermediate variables by performing shift and OR operations on the binary values corresponding to the specified quantity.
[0007] In an optional implementation, determining the intermediate variable by performing a shift operation and an OR operation on the binary values corresponding to the specified quantity includes: shifting the current variable to obtain a shifted intermediate value, wherein, upon first execution, the current variable is the binary value corresponding to the specified quantity; performing an OR operation on the current variable and the shifted intermediate value to obtain an updated current variable; repeating the above steps until a set condition is met, and using the current variable calculated by the above calculation process as the intermediate variable.
[0008] In an optional implementation, generating the nth element of the initial random sequence based on the intermediate variable includes: calculating the random weight of the nth element based on the preset seed number, the intermediate variable, and n; and performing a modulo operation on the sum of the random weight and the preset seed number to obtain the nth element.
[0009] In an optional implementation, rearranging the specified number of elements in the initial random sequence to obtain the target random sequence includes: dividing the initial random sequence into multiple sub-initial sequences; rearranging the multiple sub-initial sequences to obtain multiple rearranged sequences; and determining the target random sequence based on the multiple rearranged sequences.
[0010] In an optional implementation, rearranging the multiple sets of sub-initial sequences to obtain multiple rearranged sequences includes: using a process with the same number of sub-initial sequences, each process rearranging one set of sub-initial sequences to obtain rearranged sequences.
[0011] In an optional implementation, rearranging the multiple sets of initial sub-sequences to obtain multiple rearranged sequences includes: rearranging each set of initial sub-sequences in the following manner: determining the first exchange element from the initial sub-sequence based on i, where i is a positive integer greater than or equal to 0 and less than or equal to the number of elements in the initial sub-sequence minus 1; determining the second exchange element from the initial sub-sequence based on i, wherein the second exchange element is different from the first exchange element; exchanging the first exchange element and the second exchange element; if i is less than the number of elements in the initial sub-sequence minus 1, then incrementing i by 1 and repeating the above steps; if i is equal to the number of elements in the initial sub-sequence minus 1, then ending the above process to obtain the rearranged sequence.
[0012] Secondly, the present invention provides a sequence generation apparatus, comprising: a first generation module, configured to generate intermediate variables according to a specified number, wherein the specified number is the length of the sequence to be generated; a second generation module, configured to generate the nth element of an initial random sequence according to the intermediate variables, wherein the value of n is a positive integer greater than or equal to 1 and less than or equal to the specified number; and a rearrangement module, configured to rearrange the specified number of elements in the initial random sequence to obtain a target random sequence.
[0013] Thirdly, the present invention provides an electronic device, including: a processor and a memory, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the machine-readable instructions are executed by the processor to perform the steps of the method described in any of the foregoing embodiments.
[0014] Fourthly, the present invention provides a computer-readable storage medium storing a computer program that, when executed by a processor, performs the steps of the method described in any of the foregoing embodiments.
[0015] In the sequence generation method of this application embodiment, an initial random sequence can be generated first. After the random sequence is generated, it can be rearranged to increase the randomness and disorder of the sequence, thereby improving the security of the random sequence obtained by using this method. Attached Figure Description
[0016] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 A block diagram illustrating an electronic device provided in an embodiment of this application;
[0018] Figure 2 A flowchart of the sequence generation method provided in the embodiments of this application;
[0019] Figure 3 An exemplary flowchart of step 210 of the sequence generation method provided in this application embodiment;
[0020] Figure 4 An exemplary flowchart of step 220 of the sequence generation method provided in this application embodiment;
[0021] Figure 5 An exemplary flowchart of step 230 of the sequence generation method provided in this application embodiment;
[0022] Figure 6 An exemplary flowchart of step 232 of the sequence generation method provided in this application embodiment;
[0023] Figure 7 This is a schematic diagram of the functional modules of the sequence generation device provided in the embodiments of this application. Detailed Implementation
[0024] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.
[0025] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this application, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0026] Random sorting algorithms are widely used in various scenarios, such as generating random passwords and user accounts. One commonly used random sorting algorithm is the Fisher-Yates algorithm, which achieves a space complexity of O(n). This algorithm requires an array of length n, and by sequentially swapping the elements of this array, it achieves O(n) space complexity. Another commonly used random sorting algorithm is the Kensler algorithm, which achieves a random sorting algorithm with both time and space complexity of O(1). However, this algorithm may still have limitations compared to an n! random permutation, potentially resulting in a very limited number of generated sequences and posing security risks in scenarios using this random permutation algorithm.
[0027] Based on the aforementioned findings from research, this application provides a sequence generation method. This method first generates a set of random sequences, and then rearranges these random sequences, ensuring security while possessing a constant space and parallel processing capability as a random sorting algorithm. The sequence generation method provided in this application, as well as related products, are described below through some embodiments.
[0028] To facilitate understanding of this embodiment, the electronic device that performs the sequence generation method disclosed in this application embodiment will first be described in detail.
[0029] like Figure 1 The diagram shown is a block illustration of an electronic device. The electronic device 100 may include a memory 111 and a processor 113. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the electronic device 100. For example, the electronic device 100 may also include components that are more... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0030] The aforementioned memory 111 and processor 113 are electrically connected directly or indirectly to enable data transmission or interaction. For example, these components can be electrically connected to each other via one or more communication buses or signal lines. The aforementioned processor 113 is used to execute executable modules stored in the memory.
[0031] The memory 111 can be, but is not limited to, Random Access Memory (RAM), Read Only Memory (ROM), Programmable Read-Only Memory (PROM), Erasable Programmable Read-Only Memory (EPROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), etc. The memory 111 stores programs, and the processor 113 executes these programs upon receiving execution instructions. The methods executed by the electronic device 100 as defined in any embodiment of this application can be applied to or implemented by the processor 113.
[0032] The aforementioned processor 113 may be an integrated circuit chip with signal processing capabilities. The processor 113 may be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it may also be a digital signal processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor may be a microprocessor or any conventional processor.
[0033] The electronic device 100 in this embodiment can be used to execute various steps in the various methods provided in the embodiments of this application. The implementation process of the sequence generation method is described in detail below through several embodiments.
[0034] Please see Figure 2 This is a flowchart of the sequence generation method provided in the embodiments of this application. The following will describe... Figure 2 The specific process shown will be explained in detail.
[0035] Step 210: Generate intermediate variables according to the specified quantity.
[0036] Optionally, intermediate variables can be determined by performing shift and OR operations on the binary values corresponding to the specified quantity.
[0037] By generating intermediate variables first, the randomness of the generated initial random sequence can be improved. Optionally, the intermediate variables used to generate the initial random sequence can be determined in advance, depending on the desired length of the random sequence.
[0038] The specified quantity can be obtained in advance. This specified quantity can be a default value set in the settings. When a random sequence needs to be generated, a random sequence of length with the default value can be generated. This specified quantity can also be obtained through interaction with the user.
[0039] Step 220: Generate the nth element of the initial random sequence based on the intermediate variable.
[0040] Where n is a positive integer greater than or equal to 1 and less than or equal to the specified number.
[0041] The initial random sequence may include a specified number of elements. Therefore, by performing step 220 a specified number of times, a specified number of elements can be obtained.
[0042] In one use case, the sequence generation method can be used to generate user accounts. The number of elements required for the user account can be pre-configured. This specified number can be pre-configured, and when a user account needs to be generated later, an initial random sequence containing the specified number of elements can be generated first.
[0043] In another use case, the sequence generation method can be used to generate random passwords, the length of which can be obtained by interacting with the user and receiving the password length input by the user, and using that password length as the length of the initial random sequence.
[0044] Step 230: Rearrange the specified number of elements in the initial random sequence to obtain the target random sequence.
[0045] Optionally, the positions of each element in the initial random sequence can be adjusted to obtain the rearranged target random sequence.
[0046] In one alternative implementation, the elements in the initial random sequence can be swapped in pairs to form the rearranged target random sequence.
[0047] Optionally, elements in odd-numbered positions can be swapped with adjacent elements in odd-numbered positions, and elements in even-numbered positions can be swapped with adjacent elements in even-numbered positions. For example, if the initial random sequence is [3,1,2,0], 3 and 2 can be swapped, and 1 and 0 can be swapped to obtain the sequence [2,0,3,1], which can then be used as the target random sequence.
[0048] Alternatively, a random sampling method can be used, in which two elements are randomly selected and their positions are swapped until all elements in the random sequence have been swapped at least once.
[0049] In another alternative implementation, elements are sequentially drawn from the initial random sequence and swapped with elements that have not yet been drawn, until all elements in the initial random sequence have been drawn.
[0050] For example, taking an initial random sequence containing L elements as an example, Seq0 represents the initial random sequence, and the length of Seq0 is L:
[0051]
[0052] Here, rand()%L–n means randomly selecting a number from 1 to L–n; swap(Seq0+L-1-n,Seq0+m) means swapping each of the L-1–n elements in the Seq0 sequence with the m-th element in the Seq0 sequence.
[0053] The above cyclic process can swap each element in the initial random sequence Seq0 at least once.
[0054] In this embodiment of the application, an initial random sequence can be generated first. After the random sequence is generated, it can be rearranged to increase the randomness and disorder of the sequence, thereby improving the security of the random sequence obtained by this method.
[0055] Optionally, such as Figure 3 As shown, the intermediate variables can be determined through the following steps:
[0056] Step 211: Perform a translation operation on the current variable to obtain the translation intermediate value.
[0057] When executed for the first time, the current variable is the binary value corresponding to the specified quantity.
[0058] The current variable can be translated using the following formula, for example, w >> x. The translation distance x can be set as needed.
[0059] Step 212: Perform an OR operation between the current variable and the translation intermediate value to obtain the updated current variable.
[0060] Repeat steps a and b above until the set conditions are met, and use the current variable calculated by the above calculation process as an intermediate variable.
[0061] The setting condition can be the number of translations, for example, the setting condition can be that the number of translations reaches five, six, four, etc.
[0062] The setting condition can also be the number of loops. For example, the setting condition can be that the number of times steps 211 and 212 are executed in a loop reaches six, seven, eight, etc.
[0063] Alternatively, w can be used to represent an intermediate variable, with the initial value of the intermediate variable w = L-1; then the variable w can be updated using the formula w| = w >> x.
[0064] In this context, >> represents a right shift operation, and | represents an OR operation.
[0065] The value of x in the above formula can be set as needed. For example, x can be a power of 2. Of course, x can also be other values, such as 3 or 5.
[0066] Optionally, the variable w can undergo multiple operations w|=w>>x to obtain intermediate variables. The value of x used in each w|=w>>x operation can be different.
[0067] In one instance, the intermediate variable w can be obtained through the following five operations: w|=w>>1; w|=w>>2; w|=w>>4; w|=w>>8; w|=w>>16.
[0068] In another instance, the intermediate variable w can also be obtained through four operations: w|=w>>1; w|=w>>2; w|=w>>4; w|=w>>8.
[0069] In another example, the intermediate variable w can also be obtained through four operations: w|=w>>1; w|=w>>3; w|=w>>9; w|=w>>27.
[0070] Of course, depending on the actual application scenario, the initial random sequence can be obtained through more or fewer w|=w>>x operations. For example, the longer the sequence to be generated, the more w|=w>>x operations can be performed when obtaining the initial random sequence.
[0071] Optionally, such as Figure 4 As shown, step 220 may include steps 221 and 222.
[0072] Step 221: Calculate the random weight of the nth element based on the preset seed number, the intermediate variable, and n.
[0073] Optionally, multiple shift operations can be performed on the preset seed number, as well as multiplying it with a hexadecimal value and performing an AND operation with an intermediate variable before shifting it again. By combining the above operations multiple times, the random weight of each element can be obtained.
[0074] In one instance, the random weight of the nth element can be obtained through the following training:
[0075]
[0076]
[0077] Where p represents the preset seed number, xe170893d, 0x0929eb3f, 0x6935fa69, 0x74dcb303, 0x9e501cc3, and 0xc860a3df represent hexadecimal numbers, ^ represents the XOR operation, * represents the multiplication operation, & represents the AND operation, and the initial value of Ln is n.
[0078] Of course, depending on the needs, the above operations can be performed more or fewer times to obtain a random weight number. When performing multiplication operations, a hexadecimal number different from the hexadecimal number mentioned above can also be selected for multiplication. When performing translation operations, the translation distance can also be different from the translation distance in the above process. Specifically, the translation distance and hexadecimal value selected in the above process can be set according to actual needs.
[0079] Step 222: Perform a modulo operation on the sum of the random weight number and the preset seed number to obtain the nth element.
[0080] For example, the nth element can be calculated using the formula: (Ln+p)%L.
[0081] Wherein, variable Ln represents the random weight number at the nth position, p represents the preset seed number, and L represents the specified quantity.
[0082] The above process can calculate a set of initial random sequences with good randomness, and can also provide a data basis for the randomness of subsequent sequence rearrangements. This can improve the randomness and security of the obtained random sequences.
[0083] When the required random sequence is relatively long, the initial random sequence can be divided into multiple shorter sequences, and then rearranged separately to improve the efficiency of the rearrangement. Based on this, such as... Figure 5 As shown, step 230 may include steps 231 to 233.
[0084] Step 231: Divide the initial random sequence into multiple sub-initial sequences.
[0085] The number of initial sub-sequences can be set according to actual needs. For example, if the initial random sequence is long, the number of initial sub-sequences can be more; if the initial random sequence is short, the number of initial sub-sequences can be less.
[0086] The initial sequence lengths of each segment can be the same or different. The embodiments of this application are not limited to the length of the initial sequence of each segment.
[0087] Step 232: Rearrange the multiple sets of initial subsequences to obtain multiple sets of rearranged sequences.
[0088] Optionally, multiple processes can be started, each process performing a rearrangement of a set of sub-initial sequences. For example, using the same number of processes as the number of sub-initial sequences, each process rearranges one set of sub-initial sequences to obtain the rearranged sequence.
[0089] like Figure 6 As shown, the initial subsequences of each group are rearranged in the following manner:
[0090] Step 2321: Determine the first swap element from the initial subsequence based on i.
[0091] Where i is a positive integer greater than or equal to 0 and less than or equal to the number of elements in the initial subsequence minus 1.
[0092] For example, the first swap element can be the (i+1)th element in the currently sorted sub-initial sequence.
[0093] The first swap element can also be the right-left-1–i-th element, where right-left can be equal to the number of elements in the currently sorted sub-initial sequence.
[0094] Step 2322: Determine the second swap element from the initial subsequence based on i.
[0095] The second swap element is a different element from the first swap element.
[0096] For example, the second swap element can be an element selected from the sub-initial sequence. For instance, a random function can be used to select an element from the sub-initial sequence.
[0097] If the first swap element can be the (i+1)th element in the currently sorted sub-initial sequence, then the second swap element can be an element selected from the (i+2)th to the right-leftth elements in the sub-initial sequence. The second swap element can be a randomly selected element from the (i+2)th to the right-leftth elements using a random function.
[0098] If the first swap element can also be the right-left-1–i-th element, then the second swap element can be an element selected from the first element to the right-left-1–i-1-th element in the sub-initial sequence.
[0099] Step 2323: Swap the first swap element and the second swap element.
[0100] If i is less than the number of elements in the initial subsequence minus 1, then add 1 to i and repeat the above steps; if i is equal to the number of elements in the initial subsequence, then end the above process and obtain the rearranged sequence.
[0101] In one instance, the variable `parr` can be a long right-left sub-initial sequence, and the following loop can be used to rearrange the sub-initial sequence stored in the variable `parr`:
[0102] for(int i = 0; i <right-left-1;++i){
[0103] auto j=rand()%(right-left-i);
[0104] swap(parr+right-left-1-i,parr+j).
[0105] Here, rand()%(right-left-i) means randomly selecting an element from the first element to the first right-left-i element in the initial sequence of words, and swap(parr+right-left-1-i,parr+j) means swapping the elements at the j-th position and the right-left-1-i-th position in the variable parr.
[0106] Repeating steps 2321 to 2323 above, each sub-initial sequence can be rearranged.
[0107] Step 233: Determine the target random sequence based on the multiple rearranged sequences.
[0108] Optionally, multiple rearranged sequences can be directly concatenated into the target random sequence. The order of the multiple rearranged sequences can be the same as the original sub-initial sequences, or it can be different from the order of the sub-initial sequences.
[0109] Alternatively, a set of rearranged sequences can be drawn sequentially from multiple sets of rearranged sequences to obtain the target random sequence.
[0110] By splitting the initial random sequence into multiple sub-initial sequences, the efficiency of rearrangement can be improved and the amount of computation required for rearrangement can be reduced. In addition, the rearrangement of sub-sequences can be carried out in parallel by multiple threads, which can further improve the rearrangement efficiency.
[0111] In one instance, if you need to obtain a random permutation of length 4, the default seed number can be 10, and it can be processed simultaneously by two threads, each processing a sequence with a block size of 2.
[0112] The intermediate variable w = 3 can be calculated by using w|=w>>1;w|=w>>2;w|=w>>4;w|=w>>8;w|=w>>16.
[0113] The initial random sequence [3,1,2,0] can be calculated through steps 221 and 222 above. Then, [3,1,2,0] is divided into two sub-initial sequences [3,1] and [2,0]. The target random sequence can be obtained by rearranging these two sub-initial sequences [3,1] and [2,0].
[0114] There are many possibilities during the rearrangement process. For example, the rearrangement result can be [1,3] and [0,2], and the final target random sequence can be [1,3,0,2].
[0115] The above process, involving two rounds of processing to obtain a random sequence, followed by rearrangement, can result in a final target random sequence with good randomness. Furthermore, dividing the sequence into multiple sub-initial sequences and sorting them separately during the rearrangement stage can improve the efficiency of the rearrangement.
[0116] Furthermore, while maintaining the randomness of the generated sequence, it is also possible to suppress the memory requirements during the sequence generation process, thereby controlling the growth of memory requirements during the sequence generation process (i.e., memory does not need to be O(n)).
[0117] Based on the same application concept, this application also provides a sequence generation device corresponding to the sequence generation method. Since the principle of the device in this application is similar to that of the aforementioned sequence generation method embodiment, the implementation of the device in this application can refer to the description in the above method embodiment, and the repeated parts will not be repeated.
[0118] Please see Figure 7 This is a functional block diagram of the sequence generation apparatus provided in this application embodiment. Each module in the sequence generation apparatus in this embodiment is used to execute the steps in the above method embodiments. The sequence generation apparatus includes: a first generation module 310, a second generation module 320, and a rearrangement module 330; the contents of each module are as follows:
[0119] The first generation module 310 is used to generate intermediate variables according to a specified number, wherein the specified number is the length of the sequence to be generated;
[0120] The second generation module 320 is used to generate the nth element of the initial random sequence based on the intermediate variable, wherein the value of n is greater than or equal to 1 and less than or equal to the specified number of positive integers;
[0121] The rearrangement module 330 is used to rearrange the specified number of elements in the initial random sequence to obtain the target random sequence.
[0122] In one possible implementation, the first generation module 310 is used to determine intermediate variables by performing shift and OR operations on the binary values corresponding to the specified quantity.
[0123] In one possible implementation, the first generation module 310 is used to perform a translation operation on the current variable to obtain a translation intermediate value. When executed for the first time, the current variable is the binary value corresponding to the specified quantity. The current variable is then ORed with the translation intermediate value to obtain the updated current variable. The above process is repeated until a set condition is met, and the current variable calculated by the above calculation process is used as the intermediate variable.
[0124] In one possible implementation, the second generation module 320 is used to calculate the random weight of the nth element based on the preset seed number, the intermediate variable, and n; and to perform a modulo operation on the sum of the random weight and the preset seed number to obtain the nth element.
[0125] In one possible implementation, the rearrangement module 330 includes a partitioning unit, a rearrangement unit, and a determination unit;
[0126] A partitioning unit is used to divide the initial random sequence into multiple sub-initial sequences;
[0127] The rearrangement unit is used to rearrange the multiple sets of initial sub-sequences to obtain multiple rearranged sequences;
[0128] The determining unit is used to determine the target random sequence based on the multiple rearranged sequences.
[0129] In one possible implementation, a rearrangement unit is used to rearrange one set of sub-initial sequences through a process equal to the number of sub-initial sequences, each process rearranging the sub-initial sequences to obtain a rearranged sequence.
[0130] In one possible implementation, the rearrangement unit is used for:
[0131] The initial sequence of each group is rearranged in the following way:
[0132] Determine the first swap element from the sub-initial sequence based on i, where i is a positive integer greater than or equal to 0 and less than or equal to the number of elements in the sub-initial sequence minus 1;
[0133] Based on i, determine the second swap element from the initial sequence. This second swap element is different from the first swap element.
[0134] Swap the first and second swap elements;
[0135] If i is less than the number of elements in the initial subsequence minus 1, then add 1 to i and repeat the above steps; if i is equal to the number of elements in the initial subsequence minus 1, then end the above process and obtain the rearranged sequence.
[0136] Furthermore, embodiments of this application also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the steps of the sequence generation method described in the above method embodiments.
[0137] The computer program product of the sequence generation method provided in this application includes a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the steps of the sequence generation method described in the above method embodiments. For details, please refer to the above method embodiments, which will not be repeated here.
[0138] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0139] In addition, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0140] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks. It should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0141] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application. It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0142] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A sequence generation method, characterized in that, include: Configure a specified number of elements based on the required number of elements in the user account; or, receive the password length input by the user, where the password length is used as the specified number; wherein, the required number of elements in the user account is pre-configured; Generating intermediate variables based on the specified quantity includes: determining intermediate variables by performing shift and OR operations on the binary values corresponding to the specified quantity; wherein, the specified quantity is the length of the sequence to be generated; The process of generating the nth element of the initial random sequence based on the intermediate variable includes: calculating the random weight of the nth element based on the preset seed number, the intermediate variable, and n; performing a modulo operation on the sum of the random weight and the preset seed number to obtain the nth element; wherein the value of n is a positive integer greater than or equal to 1 and less than or equal to the specified number. The specified number of elements in the initial random sequence are rearranged to obtain the target random sequence; wherein the target random sequence serves as the user account or password.
2. The method according to claim 1, characterized in that, The step of determining intermediate variables by performing shift and OR operations on the binary values corresponding to the specified quantity includes: The current variable is shifted to obtain the shifted intermediate value. When executed for the first time, the current variable is the binary value corresponding to the specified quantity. The current variable is ORed with the translation intermediate value to obtain the updated current variable; Repeat the above steps until the set conditions are met, and use the current variable calculated in the above steps as an intermediate variable.
3. The method according to any one of claims 1-2, characterized in that, The step of rearranging the specified number of elements in the initial random sequence to obtain the target random sequence includes: The initial random sequence is divided into multiple sub-initial sequences; The multiple sets of initial sub-sequences are rearranged to obtain multiple sets of rearranged sequences; Based on the multiple rearranged sequences, the target random sequence is determined.
4. The method according to claim 3, characterized in that, The step of rearranging the multiple sets of initial sub-sequences to obtain multiple sets of rearranged sequences includes: Each process rearranges one set of sub-initial sequences using the same number of processes as the number of sub-initial sequences to obtain rearranged sequences.
5. The method according to claim 3, characterized in that, The step of rearranging the multiple sets of initial sub-sequences to obtain multiple sets of rearranged sequences includes: The sub-initial sequences described in each group are rearranged in the following manner: The first swap element is determined from the sub-initial sequence based on i, where i is a positive integer greater than or equal to 0 and less than or equal to the number of elements in the sub-initial sequence minus 1; Based on i, the second swap element is determined from the initial sequence, and the second swap element is different from the first swap element; Swap the first swap element and the second swap element; If i is less than the number of elements in the initial subsequence minus 1, then i is incremented by 1, and the above steps are repeated; if i is equal to the number of elements in the initial subsequence minus 1, then the above process ends, and the rearranged sequence is obtained.
6. A sequence generation apparatus, characterized in that, include: The determining module is used to configure a specified number of elements according to the number of elements required to be included in the user account; or, to receive the password length input by the user and use the password length as the specified number; wherein, the number of elements required to be included in the user account is pre-configured; The first generation module is used to generate intermediate variables according to a specified number, wherein the specified number is the length of the sequence to be generated; The second generation module is used to generate the nth element of the initial random sequence based on the intermediate variable, wherein the value of n is greater than or equal to 1 and less than or equal to the specified number of positive integers; The rearrangement module is used to rearrange the specified number of elements in the initial random sequence to obtain a target random sequence; wherein the target random sequence serves as a user account or password. The first generation module is configured to generate intermediate variables according to the specified quantity, including: determining the intermediate variables by performing a shift operation and an OR operation on the binary values corresponding to the specified quantity; wherein, the specified quantity is the length of the sequence to be generated; The second generation module is used to calculate the random weight of the nth element based on the preset seed number, the intermediate variable, and n; and to perform a modulo operation on the sum of the random weight and the preset seed number to obtain the nth element.
7. An electronic device, characterized in that, include: The processor and memory, wherein the memory stores machine-readable instructions executable by the processor, wherein when the electronic device is running, the machine-readable instructions are executed by the processor to perform the steps of the method as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, performs the steps of the method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Interleaved sequence constructing method, interleaving-based information processing method and transceiver
CN107769842A
Lossless watermarking method and lossless watermarking detection method
CN110415156A