RSA encryption and decryption method

By generating mutually different large prime numbers at the receiving end and using prime number cross-arc representation and factorial section-by-section method, the problem of low efficiency of large prime number generation in RSA encryption and decryption method is solved, the efficiency and reliability of RSA encryption and decryption process are improved, and the security of data encryption system is enhanced.

CN116506126BActive Publication Date: 2025-10-17HUAZHONG UNIV OF SCI & TECH
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310364374.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-04-07
Publication Date
2025-10-17
Estimated Expiration
2043-04-07

AI Technical Summary

Technical Problem

Existing RSA encryption and decryption methods are inefficient in generating large prime numbers and are unable to meet the security requirements of modern information systems.

Method used

By generating two different large prime numbers at the receiving end, and using the basic prime number library to generate RSA public and private keys based on the cross-arc representation of prime numbers and the prime factorial section-by-section method, the efficiency and accuracy of large prime number generation are improved.

Benefits of technology

It improves the computational efficiency and encryption reliability of the RSA encryption and decryption process, reduces the time required to solve large prime numbers, and enhances system confidentiality in the field of data encryption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116506126B_ABST
    Figure CN116506126B_ABST
Patent Text Reader

Abstract

The application discloses an RSA encryption and decryption method, and belongs to the field of information security. The method comprises the following steps: generating two different large prime numbers at a receiving end; generating an RSA public key and a private key according to the two different large prime numbers at the receiving end, and transmitting the RSA public key to a sending end; encrypting information to be encrypted by using the RSA public key at the sending end to obtain ciphertext, and then transmitting the ciphertext to the receiving end; decrypting the ciphertext by using the RSA private key at the receiving end to obtain plaintext; and when generating the large prime numbers, solving the prime numbers and establishing a basic prime number library based on the cross-arc representation of the prime numbers and the prime number factorial segmentation method, then generating seed points by using the basic prime number library, and continuously expanding the prime number factorial segmentation to obtain large prime numbers that meet the requirements and pass the primality test, so that the large prime numbers can be more accurately and efficiently obtained, the calculation efficiency of the RSA encryption and decryption process is improved, and the reliability of encryption is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application belongs to the field of information security, and more particularly, to an RSA encryption and decryption method. BACKGROUND

[0002] The high-speed development of modern society cannot be separated from the development of Internet system and information system, and the foundation of Internet system and information system is the security of information, which cannot be separated from encryption algorithm and protocol. In the Internet system, information is transmitted through digital signals. Because the Internet system serves the whole world, the data transmitted on the Internet is public. However, the data transmitted on the Internet not only contains public information, but also contains secret information. In order to transmit secret information in the public Internet, encryption algorithm and protocol must be used, and the key to implementing encryption algorithm and protocol is to use the key. The information system is the same, various information needs to use encryption algorithm for security, and also cannot be separated from the use of the key.

[0003] The key itself is a string of numbers. When transmitting information, the Internet system and the information system first need to use the key to encrypt it at the sending end, and then use the key to decrypt it at the receiving end, so that the receiving end can correctly identify the information. If the key can be well protected, only the sending end and the receiving end know the key, then the work of the security system will be effective. However, if the key needs to be transmitted on the network, or needs to be electronically signed, key exchange, etc., a more effective key generation method must be used to more reliably ensure the security of the system.

[0004] The method of using large prime numbers to generate keys is very effective. The most typical is the RSA public key encryption method proposed by Ronald Rivest, Adi Shamir and Leonard Adleman in 1977. RSA algorithm is based on a very simple number theory fact: it is very easy to multiply two large prime numbers, but it is extremely difficult to factorize a number into two prime numbers, so the product can be publicly disclosed as an encryption key. RSA is currently the most influential and most commonly used public key encryption algorithm, which can resist most of the known password attacks so far, and has been recommended by ISO as a public key data encryption standard.

[0005] To implement RSA encryption, first, large prime numbers need to be obtained. When the prime number is large, because the large prime number is sparse and difficult to confirm, solving the large prime number becomes a very time-consuming process. SUMMARY

[0006] In view of the above defects or improvement needs of the prior art, the present application provides an RSA encryption and decryption method, thereby solving the technical problem that the efficiency of the existing RSA encryption and decryption method needs to be improved.

[0007] To achieve the above object, according to the first aspect of the present application, there is provided an RSA encryption and decryption method, comprising:

[0008] S1, generating two different large prime numbers at a receiving end;

[0009] S2, generating RSA public key and private key according to the different large prime numbers at the receiving end, and transmitting the RSA public key to a sending end;

[0010] S3, encrypting the information to be encrypted by using the RSA public key to obtain ciphertext, and sending the ciphertext to the receiving end;

[0011] S4, decrypting the ciphertext by using the RSA private key to obtain plaintext.

[0012] Preferably, the generation process of the large prime number comprises:

[0013] A1, creating an array;

[0014] A2, constructing an initial prime factorial segment; wherein the initial prime factorial segment is a prime p k factorial segment, the prime p k factorial segment is an interval [0, p k ] on a coordinate axis with the origin as the starting point and the size equal to the factorial value p k ! of the prime p k , p k ! = p1p2…p k , p1, p2, …, p k are prime numbers arranged in ascending order, the type of integer points in the interval is prime points, composite points or pending points; the prime p k is set as the current prime number; wherein for the initial prime factorial segment, p k ≥ 2;

[0015] A3, taking the first pending point located to the right of the current prime number on the coordinate axis as the prime p k+1 ;

[0016] A4, judging whether the product of the current block length and the prime p k+1 exceeds the limit of the array, if yes, going to A8, if not, going to A5; wherein the current block is a storage structure for storing the current prime factorial segment;

[0017] A5, taking the current prime p k factorial segment as the first segment, and copying the first segment p k+1 times;-1 part as a continuation section, so that the type of the resulting continuation section point is the same as the first section, and the first section and each continuation section are sequentially spliced in the coordinate axis to obtain a prime number p k+1 Factorial section;

[0018] A6, the prime number p k+1 is taken as the current prime number p k ;

[0019] A7, using the current prime number p k , the prime number p k is taken as the current prime number p k ; The points corresponding to the prime points less than p k in the first section are set to composite points, and all 2p k+1 multiple points in the array are set to composite points; return to A3;

[0020] A8, copy and sequentially splice the current prime factorial section to fill the array;

[0021] A9, the prime number p k is taken as the current prime number p k ;

[0022] A10, using the current prime number p k , the prime factorial section after splicing is screened: all 2p multiple points in the array from the beginning to the end are set to composite points;

[0023] A11, determine whether there is a next pending point, if yes, set it as a prime number p k+1 and return to A9, if not, end, output all prime numbers as large prime numbers, and place all prime numbers in the first prime number library.

[0024] Preferably, the type division of the integer points in the interval is as follows:

[0025] 1) all prime numbers not greater than the prime number p k are taken as known prime numbers, and the points where the known prime numbers are located are set as prime points, and 1 is set as a pending point;

[0026] 2) determine whether other integer points in the interval are control points of known prime numbers; if yes, set the point as a composite point, otherwise set it as a pending point;

[0027] The control point is the end point of the control arc, and it does not include the end point of the generated arc; the generated arc is the arc connecting the origin of the coordinate axis and the prime point p k , the control arc has the same size as the generated arc, and the distance between the starting point of the control arc and the starting point of the generated arc on the coordinate axis is an integer multiple of p k .

[0028] Preferably, the generating process of the large prime number comprises:

[0029] B1, assuming that the current pending point x=1, taking a prime number p k as the current prime number;

[0030] B2, taking the next prime number value p k+1 from the first prime number library;

[0031] B3, randomly generating an extension number m, and determining the next pending point y according to m, wherein 1≤m≤p k+1 , y=(m-1)p k !+x;

[0032] B4, judging whether y is divisible by p k+1 , if yes, going to B3, if no, going to B5;

[0033] B5, judging whether the size of the point y meets the preset RSA key generation requirement, if yes, going to B6, if no, setting x=y, p k =p k+1 , taking the next prime number value p k+1 from the first prime number library, and going to B3;

[0034] B6, judging whether the point y is a composite point, if yes, going to B3, if no, outputting y as a large prime number.

[0035] Preferably, the generating process of the large prime number comprises:

[0036] C1, determining the current prime number p k in the second prime number library;

[0037] C2, in the second prime number library, randomly selecting a pending point from the interval [ p1p2…p k -p k ] as the current pending point x;

[0038] C3, taking the first pending point located on the right side of the current prime number on the coordinate axis as the prime number p k+1 ;

[0039] C4, randomly generating an extension number m, and determining the next pending point y according to m, wherein 1≤m≤p k+1 , y=(m-1)p k !+x;

[0040] C5, judging whether y is divisible by p k+1 , if yes, going to C4, if no, going to C6;

[0041] C6, determine whether the size of point y meets the preset RSA key generation requirements. If so, enter C7, if not, set x = y, p k =p k+1 , get the next prime value p from the first prime number library k+1 , go to C4;

[0042] C7, determines whether point y is a composite point. If so, go to C4. If not, output y as a large prime number.

[0043] Preferably, the process of establishing the second prime number library includes:

[0044] 1) Create an array;

[0045] 2) Constructing an initial prime factorial node; wherein the initial prime factorial node is a prime number p k Factorial section, the prime number p k The factorial node of is the number of prime numbers p on the coordinate axis starting from the origin. k Factorial value p k ! The interval [0, p k ! ), p k ! =p1p2…p k ,p1,p2,…,p k are prime numbers arranged in ascending order, and the types of integer points in the interval are prime points, composite points or undetermined points; the prime number p k Set to the current prime number;

[0046] 3) Take the first undetermined point on the coordinate axis to the right of the current prime number as the prime number p k+1 ;

[0047] 4) Determine the current block length and prime number p k+1 Whether the product of exceeds the limit of the array, if so, then end, output the current prime number and all pending points, and place them in the second prime number library; if not, go to 5); wherein the current block is a storage structure for storing the current prime number factorial node;

[0048] 5) Take the current prime factorial section as the first section, and copy the type of each point in the first section to p k+1 -1 as a sequel, so that the type of the midpoint of the sequel is the same as that of the first section, and the first section and each sequel are sequentially spliced ​​to obtain a prime number p k+1 Factorial Festival;

[0049] 6) The prime number p k+1 As the current prime number p k ;

[0050] 7) Use the current prime number p k For prime number p kPrime points corresponding to the first section in each continuation section are set as composite points, and all 2p multiples in k are set as composite points; return A3; wherein the prime points corresponding to the first section in each continuation section do not include the current prime point.

[0051] According to a second aspect of the present application, an RSA encryption and decryption system is provided, comprising: a computer readable storage medium and a processor;

[0052] The computer readable storage medium is configured to store executable instructions;

[0053] The processor is configured to read the executable instructions stored in the computer readable storage medium, and execute the method according to the first aspect.

[0054] According to a third aspect of the present application, a computer readable storage medium is provided, wherein the computer readable storage medium stores computer instructions, and the computer instructions are configured to enable the processor to execute the method according to the first aspect when executed.

[0055] In general, compared with the prior art, the above technical solutions conceived by the present application can achieve the following beneficial effects:

[0056] 1. The RSA encryption and decryption method provided by the present application comprises: generating two different large prime numbers at a receiving end; generating RSA public key and private key according to the different large prime numbers at the receiving end, and transmitting the RSA public key to a sending end; encrypting plaintext by using the RSA public key to obtain ciphertext, and then sending the ciphertext to the receiving end; decrypting the ciphertext by using the RSA private key to obtain plaintext at the receiving end; wherein when generating large prime numbers, based on the arc-cross representation of prime numbers and the prime factorial section segmentation method, prime numbers are solved and a basic prime number library is established, then a seed point is generated by using the basic prime number library, and large prime numbers meeting the requirements and passing the primality test are obtained through continuous expansion of the prime factorial section, so that the large prime numbers can be obtained more accurately and efficiently, thereby improving the calculation efficiency of the RSA encryption and decryption process and enhancing the reliability of encryption.

[0057] 2、The RSA encryption and decryption method provided by the application, when generating a large prime number, only has array assignment and addition operation, and multiplication and division operation is extremely small, and each calculation is limited in one prime number factorial section, so the operation amount is small, thereby improving the calculation efficiency of the RSA encryption and decryption process; the basic prime number library stored by the application can be used for direct inquiry of small prime numbers and searching of large prime numbers. When generating a large prime number, the searching is started from a larger number, thereby reducing the solving time of the large prime number. Since the basic prime number library occupies a small storage amount, is used for a small number of times, and is exited immediately after use, the application of other application systems is not affected; the above large prime number generation process can be widely applied in the data encryption field, and the security of the system is enhanced. BRIEF DESCRIPTION OF DRAWINGS

[0058] Figure 1 is a typical prime number coordinate axis schematic diagram provided by the embodiment of the application;

[0059] Figure 2 is a schematic diagram of generating a cross-arc and controlling a cross-arc provided by the embodiment of the application;

[0060] Figure 3 (a), (b) and (c) in are dynamic generation process diagrams of prime numbers 2, 3 and 5 respectively provided by the embodiment of the application;

[0061] Figure 4 is a hierarchical diagram of prime numbers provided by the embodiment of the application;

[0062] Figure 5 is a factorial section diagram of prime number 2 provided by the embodiment of the application;

[0063] Figure 6 is a factorial section diagram of prime number 3 provided by the embodiment of the application;

[0064] Figure 7 is a factorial section diagram of prime number 5 provided by the embodiment of the application;

[0065] Figure 8 is a factorial solving principle diagram of prime numbers provided by the embodiment of the application;

[0066] Figure 9 is a flowchart of a standard large prime number factorial solving method provided by the embodiment of the application;

[0067] Figure 10 is a flowchart of a large prime number generation method required for RSA encryption provided by the embodiment of the application;

[0068] Figure 11 is a flowchart of another standard large prime number solving method provided by the embodiment of the application. DETAILED DESCRIPTION

[0069] In order to make the objects, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and not to limit the present application. In addition, the technical features involved in the various embodiments of the present application described below can be combined with each other as long as they do not conflict with each other.

[0070] The existing RSA encryption and decryption method is usually developed based on the definition of prime number, that is, a number is randomly generated, and if the number can only be divided by 1 and itself, it is a prime number. This method has extremely huge calculation amount, and needs to perform division operation on all numbers smaller than it, so it is improved that if the number cannot be divided by the numbers (not including 1) within its square root, it is a prime number.

[0071] As early as in ancient Greece, Eratosthenes proposed a method for finding prime numbers, called the Eratosthenes sieve method. The method is to first list all positive integers less than N, remove 1, and then remove all multiples of the prime numbers less than or equal to the square root of N except the prime numbers themselves, and the remaining numbers are the prime numbers less than N.

[0072] When removing numbers, you can start from the square of each number, that is, start from the square of each prime number to remove its multiples, which can reduce the workload of removing.

[0073] The Eratosthenes sieve method is the most rigorous and scientific method for solving prime numbers, but it has huge calculation amount and is difficult to be used for solving large prime numbers. There are three steps to obtain large prime numbers in modern times: initial value selection, increment transformation, and primality detection. There are two methods for initial value selection. One method is to randomly select an odd number, and the other method is to select an odd number coprime with the product of small prime numbers. The increment transformation is to give an increment function to obtain a large prime number by transforming the initial value. The primality detection is to detect the obtained large prime number to determine whether it is a prime number.

[0074] Before introducing the RSA encryption and decryption method provided by the embodiments of the present application, the related definitions of prime numbers are explained as follows:

[0075] Prime number and composite number

[0076] Definition 1: A positive integer greater than 1 is called a prime number if it can only be divided by 1 or itself.

[0077] Definition 2: A positive integer is called a composite number if it can be divided by 1 or itself, and can also be divided by other numbers.

[0078] The number 1 is special, it is neither a prime number nor a composite number, it is called a special number. ​

[0079] Definition 3: The property of a positive integer whether it is a prime number is called primality.

[0080] Arc of a prime number

[0081] Definition 4: The point of a prime number on the coordinate axis is called a prime point, and the arc connecting the origin of the prime number coordinate system and a prime point is called the generating arc of the prime number.

[0082] Definition 5: The generating arc of a prime number p is copied and placed in the prime number coordinate system in a head-to-tail manner, resulting in an infinite number of arcs. Such arcs are called control arcs of the prime number p, and their endpoints are called control points (excluding prime points that coincide with the generating arc).

[0083] Definition 6: The coordinate axis represented by the prime number generating arc and the prime number control arc is called the prime number arc coordinate axis, abbreviated as the prime number coordinate axis.

[0084] Figure 1 The figure shows a typical prime number coordinate axis, which represents the generating arcs of prime numbers 2, 3, 4, 7, 11, and 13.

[0085] As shown in Figure 2 , a prime number has only one generating arc, but there are an infinite number of control arcs. The prime number arcs are represented by dashed lines.

[0086] Definition 7: In the prime number generation process, points that cannot be determined as prime numbers or composite numbers temporarily are called pending points.

[0087] On the prime number coordinate axis, there are three types of points: prime points, composite points, and pending points. Composite points can be represented by a circle ●, prime points can be represented by a square ■, pending points can be represented by a hollow circle ○, and special point 1 can be represented by a triangle ▲ or a hollow circle ○. When drawing the prime number arc coordinate axis, points that are not marked with any symbol may be one of the three types of points, i.e., they may be composite points, prime points, or pending points, but they are not specifically marked at this time, so they are not marked.

[0088] Prime number generation process

[0089] Assuming that all prime numbers in the prime number coordinate system are dynamically generated, i.e., in the initial state, there are only positive integer points on the prime number coordinate system, and there are no prime numbers or their arcs. Then, by moving along the positive direction of the coordinate axis point by point, each prime number arc and its control arc are determined, and thus all prime numbers in the entire prime number coordinate system are determined. Therefore, another definition of prime numbers is given as follows.

[0090] Definition 8: The generation of prime numbers is a dynamic adding process. First, all points on the coordinate axis greater than 1 are set as undetermined points, and 1 is a special point, not a prime number. When moving along the coordinate axis in the positive direction, if the current point is not a control point of a prime number, the point is defined as a prime number point and added to the current prime number set.

[0091] Figure 3 (a), (b), (c) in the figure respectively represent the dynamic generation process of prime numbers 2, 3, and 5.

[0092] Hierarchy of prime number generation

[0093] Definition 9: The interval [p, p 2 ) where the current prime number p is located is called the prime control layer, simply called the control layer or the current layer, and the interval [p 2 , ∞) affected by it is called the prime influence layer, simply called the influence layer.

[0094] As shown in Figure 4 , the solid line represents the control layer of a prime number, and the dashed line represents the influence layer of the prime number.

[0095] Among them, layer 0 and layer 1 are specially defined for consistency.

[0096] Any prime number p is in the pth layer, and its control layer interval is [p, p 2 ), and the influence layer interval is [p 2 , ∞).

[0097] Here, p in the pth layer is the value of the prime number, and the layer number is not continuous, but is defined according to the prime number. There is the following theorem.

[0098] Theorem 1: In the process of dynamically determining the prime number p, the primality of all positive integers in the current prime number layer [p, p 2 ) is determined, while the primality of some positive integers in its influence layer (p 2 , ∞) is undetermined.

[0099] Theorem 2: A number is a prime number if it cannot be divided by all prime numbers within its square root.

[0100] Prime factorial section

[0101] Definition 10: If prime numbers p1, p2, …, p k are arranged in ascending order, then their product p1p2…p k is called the prime p k factorial, denoted as p k !, and the interval with a size equal to the prime p k factorial value is called the prime p k factorial section.

[0102] When any prime number is generated, the prime coordinate axis starts from the origin and moves along the prime number p. k The factorial section size is divided into sections, because p1p2…p k are prime numbers p1, p2, …, p k The least common multiple of the prime numbers in these factorial sections is the same as the shape of the generating arc and the controlling arc, that is, every p1p2…p k , whose prime shape is repeated once across the arc.

[0103] For example, the arc span structure of the factorial node of prime numbers 2, 3, and 5 is as follows Figure 5 、 Figure 6 、 Figure 7 If we continue to draw all the prime number span arc diagrams, the span arc structure in the latter part is exactly similar to these factorial sections.

[0104] Copying and filtering of prime factorial sections

[0105] In the process of generating prime numbers, each time a prime number p is generated k+1 , a new prime number p will be formed k+1 Factorial section, which is the sum of the previous prime number p k The expansion of the factorial section is from the prime number p k Factorial node-span arc structure extended to prime number p k+1 The factorial section structure, its expansion process is as follows Figure 8 As shown, when the prime factorial section of prime number 5 is expanded, the arcs spanning prime numbers 2 and 3 are not drawn, but only the point type is given. The range within the dotted line is the current prime factorial section.

[0106] Definition 11: If the currently added prime numbers are p1, p2, ..., p k , then copy the current prime factorial across the arc and its endpoint type p k+1 The operation of sequentially connecting the prime factorial section is called the replication of the prime factorial section. The replicated section is called the first section, and the replicated section is called the continuation section or the replication section. k+1 The operation of marking the points in the factorial section with point types is called filtering.

[0107] Figure 8 Only the copy operation is given, no filtering operation is shown.

[0108] Because each prime factorial section has the same structure, only one prime number p needs to be implemented each time it is expanded. k+1 Factorial Festival.

[0109] The purpose of copying is to construct the current prime number p k+1 The arcs across the factorial section form a complete prime number p k+1The sieve step is divided into two steps.

[0110] In the first step, the points in the first p1, p2, …, p k The points in the first p1, p2, …, p

[0111] In the second step, the points in the first p The points in the first p k+1 The points in the first p k+1 The points in the first p The points in the first p k+1 The points in the first p

[0112] In the process of expanding the prime-numbered factorial sieve, if the copy operation is performed, the undetermined points in the first sieve will still be in the form of undetermined points in the subsequent sieve, if the undetermined points in the first sieve are determined to be prime-numbered points, the undetermined points will become composite-numbered points in the subsequent sieve, and will continue to be of the composite-numbered point type in the subsequent expansion process.

[0113] The embodiment of the present application provides an RSA encryption and decryption method, when a receiving end needs a sending end to transmit important information to the receiving end, comprising the following steps:

[0114] S1, generating two different large prime numbers in the receiving end.

[0115] Specifically, two different large prime numbers are generated in the receiving end, the two large prime numbers are equal in order of magnitude or have little difference, but have a large difference in value. The system generally generates a new large prime number when needed, and can also generate a large prime number in advance using idle time, but cannot use a used large prime number.

[0116] S2, generating RSA public keys and private keys according to the different large prime numbers in the receiving end, and transmitting the RSA public keys to the sending end.

[0117] Specifically, the receiving end combines and transforms the two generated large prime numbers to obtain two keys, one is a public encryption key for the receiving end, referred to as a public key, and the other is a private decryption key for the receiving end, referred to as a private key.

[0118] The receiving end sends the public key to the sending end through a network or other means.

[0119] The most critical step in generating the key is to generate a large prime number.

[0120] S3, the sending end encrypts the information to be encrypted using the RSA public key to obtain ciphertext, and sends the ciphertext to the receiving end.

[0121] Specifically, after receiving the public key, the sender uses the public key to encrypt the information to be sent to the receiver, that is, the plain text, to obtain the ciphertext.

[0122] The sender sends the encrypted ciphertext to the receiver through the network.

[0123] S4, the receiving end uses the RSA private key to decrypt the ciphertext to obtain plaintext.

[0124] Specifically, after the receiving end receives the ciphertext encrypted by the sending end, it uses its own private key to decrypt the ciphertext to obtain the plaintext, thus completing the task of receiving the information.

[0125] It can be understood that the receiving end performs a combined transformation based on two large prime numbers to obtain the public key and the secret key, the sending end encrypts the plaintext according to the public key provided by the receiving end to form a ciphertext, and the receiving end uses its own private key to decrypt the ciphertext after receiving the ciphertext encrypted by the sender to obtain the plaintext. All of these use existing technologies and will not be repeated here.

[0126] Preferably, the process of generating the large prime number includes:

[0127] A1, create an array;

[0128] A2, constructing an initial prime factorial node; wherein the initial prime factorial node is a prime number p k (p k ≥2) factorial section, the prime number p k The factorial node of is a square on the coordinate axis with the origin as the starting point and its size is equal to the prime number p k Factorial value p k ! The interval [0, p k ! ), p k ! =p1p2…p k ,p1,p2,…,p k are prime numbers arranged in ascending order, and the types of integer points in the interval are prime points, composite points or undetermined points; the prime number p k Set to the current prime number;

[0129] A3, take the first undetermined point on the coordinate axis to the right of the current prime number in the interval as the prime number p k+1 ;

[0130] A4, determine the current block length and prime number p k+1 Whether the product of exceeds the limit of the array, if so, go to A8, if not, go to A5; wherein the current block is a storage structure for storing the current prime factorial node;

[0131] A5, the current prime number p kThe factorial section is taken as the first section, and the first section is copied to p k+1 -1 as a subsequent section, so that the type of the midpoint of the obtained subsequent section is the same as that of the first section, and the first section and each subsequent section are sequentially spliced ​​on the coordinate axis to obtain a prime number p k+1 Factorial Festival;

[0132] A6, the prime number p k+1 As the current prime number p k ;

[0133] A7, using the current prime number p k For prime number p k Factorial section is filtered: the points in each subsequent section corresponding to the prime points in the first section are set as composite points, and the All 2p k The multiple points are set as composite points; return to A3; wherein the prime points corresponding to the first section in each subsequent section do not include the current prime point;

[0134] A8, copies and sequentially concatenates the current prime factorial section to fill the array;

[0135] A9, the prime number p k+1 As the current prime number p k ;

[0136] A10 uses the current prime number in A9 to filter the concatenated prime factorial sections: All 2p to the end k Multiple points are set as composite points;

[0137] A11, determine whether there is a next undetermined point, if so, let it be a prime number p k+1 And then return to A9, if not, then end, output all prime numbers as large prime numbers, and place all prime numbers in the first prime number library.

[0138] Specifically, if Figure 9 As shown, the process of generating the large prime number includes:

[0139] 1) Initialization. Create an array number to store the prime and composite number flags for each point in the prime factorial section;

[0140] 2) Construct the initial prime factorial section. Here, the storage structure of the prime factorial section is called a block. The prime factorial section of 3 can be defined as the initial block, that is, the elements 0-5 in number are set as prime numbers, composite numbers, and pending numbers, where points 2 and 3 are prime numbers, points 0 and 4 are composite numbers, and points 1 and 5 are pending numbers. Record that the length of the current factorial block is 6, and the current prime number is p k =3;

[0141] 3) Find the first undetermined point as the next prime number pk+1 ;

[0142] 4) Calculate the current block length and prime number p k+1 If the value exceeds the array bounds, go to 9);

[0143] 5) Copy the current block to p k+1 -1 parts, which are sequentially connected to form a new prime number solving block, that is, the prime number p is obtained k+1 Factorial Festival;

[0144] 6) Change p k+1 Set to the current prime number p k , record the new current factorial block length;

[0145] 7) Use the current prime number to filter the prime factorial section, set the prime point corresponding to the first section in the subsequent section as the composite number flag, and All 2p k The multiple points are set to composite numbers; wherein the prime points corresponding to the first section in each subsequent section do not include the current prime point;

[0146] 8) Go to step 3);

[0147] 9) Copy (copy the point type) and splice the current prime factorial node to fill the subsequent data in the number array with the composite number and the pending point flag;

[0148] 10) k+1 Set to the current prime number p k ;

[0149] 11) Use the current prime number to filter the prime factorial section and put the prime factorial in the array number All 2p to the end k The multiple points are set to composite numbers;

[0150] 12) Find the next pending point p k+1 ;

[0151] 13) If p k+1 If it does not exist, exit and get the type of each point as composite number or prime number. If there is no undetermined point, output all prime numbers as large prime numbers and place all prime numbers in the first prime number library;

[0152] 14) Go to 10).

[0153] Preferably, the integer points in the interval are divided into types as follows:

[0154] 1) will be no greater than a prime number p k All prime numbers of are known prime numbers, (prime number p k Generally, a smaller known prime number is selected, such as the prime number pk Optional prime number 3), the prime number p k All prime numbers not greater than p in the factorial section k The point where the prime number of is located is set as a prime point;

[0155] 2) Set 1 as the pending point;

[0156] 3) Determine whether the other points are control points of known prime numbers; if so, set the point as a composite point, otherwise set it as an undetermined point;

[0157] The control point is the endpoint of the control span arc, and it does not include the endpoint of the generated span arc; the generated span arc is the point connecting the origin of the coordinate axis and the prime point p k The span arc of the control span arc is the same size as the generated span arc, and the distance between the starting point and the starting point of the generated span arc on the coordinate axis is p k An integer multiple of .

[0158] It is understandable that due to the limited computing and storage capabilities of computers, that is, the influence of the maximum array number that can be created, the above-mentioned methods A1 to A11 for generating prime numbers can only obtain large prime numbers that are relatively small relative to the encryption requirements. If larger prime numbers are required to further improve security, based on this, another method for generating large prime numbers B1 to B7 or C1 to C7 can be used to provide large prime numbers for the operation of the encryption system at any time.

[0159] Preferably, the process of generating the large prime number includes:

[0160] B1, let the current undetermined point x = 1, and set the prime number p k as the current prime number;

[0161] B2, from the first prime number library (wherein the prime numbers are arranged in ascending order, and p k Less than p k+1 ) to get the next prime value p k+1 ;

[0162] B3, randomly generate an extension number m, and determine the next pending point y based on m, where 1≤m≤p k+1 , y=(m-1)p k !+x;

[0163] B4, determine whether y can be p k+1 If it is divisible, go to B3, if not, go to B5;

[0164] B5, determine whether the size of point y meets the preset RSA key generation requirements. If so, proceed to B6. If not, set x = y, p k =p k+1 , get the next prime value p from the first prime number libraryk+1 go to B3;

[0165] B6, judge whether point y is a composite point, if yes, go to B3, if no, output y as a large prime number.

[0166] Preferably, the generating process of the large prime number comprises:

[0167] C1, determine a current prime number p in the second prime number library k ;

[0168] C2, in the second prime number library, randomly select a pending point from the interval as a current pending point x;

[0169] C3, take the first pending point located right to the current prime number p in the interval on the coordinate axis as a prime number p k+1 ;

[0170] C4, randomly generate an extension number m, and determine a next pending point y according to m, wherein 1≤m≤p k+1 , y=(m-1)p k !+x;

[0171] C5, judge whether y can be divided by p k+1 , if yes, go to C4, if no, go to C6;

[0172] C6, judge whether the size of point y meets the preset RSA key generation requirement, if yes, go to C7, if no, let x=y, p k =p k+1 , obtain a next prime number value p k+1 from the first prime number library, and go to C4;

[0173] C7, judge whether point y is a composite point, if yes, go to C4, if no, output y as a large prime number.

[0174] Preferably, the establishing process of the second prime number library comprises:

[0175] 1) create an array;

[0176] 2) construct an initial prime number factorial segment; wherein the initial prime number factorial segment is a factorial segment of a prime number p k (p k ≥2), the factorial segment of the prime number p k is an interval [0, p k !] on the coordinate axis with the origin as the starting point and the size equal to the factorial value p k ! of the prime number p k , p k !=p1p2…p k,p1,p2,…,p k are prime numbers arranged in ascending order, and the types of integer points in the interval are prime points, composite points or undetermined points; the prime number p k Set to the current prime number;

[0177] 3) Take the first undetermined point on the coordinate axis to the right of the current prime number as the prime number p k+1 ;

[0178] 4) Determine the current block length and prime number p k+1 Whether the product of exceeds the limit of the array, if so, then end, output the current prime number and all pending points, and place them in the second prime number library; if not, go to 5); wherein the current block is a storage structure for storing the current prime number factorial node;

[0179] 5) Take the current prime factorial section as the first section, and copy the type of each point in the first section to p k+1 -1 as a subsequent section, so that the type of the midpoint of the obtained subsequent section is the same as that of the first section, and the first section and each subsequent section are sequentially spliced ​​to obtain a prime number p k+1 Factorial Festival;

[0180] 6) The prime number p k+1 As the current prime number p k ;

[0181] 7) Use the current prime number p k For prime number p k Factorial section is filtered: the prime number points corresponding to the first section in each subsequent section are set as composite points, and the All 2p k The multiple points are set as composite points; return to A3; wherein the prime points corresponding to the first section in each subsequent section do not include the current prime point;.

[0182] From the above description, it can be seen that the difference between methods B1 to B7 and methods C1 to C7 mainly lies in the first two steps, that is, the different ways of determining the current prime number and the current point to be determined.

[0183] Specifically, to determine whether a number N is prime, we need to use For large prime numbers, it is very likely that they will exceed the storage and calculation range of the computer, so the present invention proposes another method for solving large prime numbers.

[0184] The process of generating prime numbers is an expansion process of prime factorial sections. In this expansion process, the type of the point in the first section is copied to the subsequent sections. If a point in the first section is a prime or composite point, then the corresponding point in its subsequent section is also a composite point, and the corresponding point in the subsequent section is still a pending point. So if a point is a prime number p k+1If it is not a prime number, then it is not a prime number in the previous prime factorial section m The point in the corresponding position in the factorial section of order m < k + 1 should be a pending point. To obtain a large prime number, it must be ensured that the point in the corresponding position in all the previous prime factorial sections is a pending point. The method of finding a large prime number is as follows.

[0185] Let the current prime factorial section be p k The value of a pending point in the prime factorial section is x, i.e., x is a pending point in the interval The prime generating process is a process of expanding from the prime factorial section of p k to the prime factorial section of p k+1 Therefore, the x point will be at the y point in the prime factorial section of p k+1 , i.e., y = (m - 1) p k ! + x, 1 ≤ m ≤ p k+1 Here, m is called the prime factorial section expansion number, abbreviated as expansion number. Because y = (m - 1) p k ! + x can only have one number divisible by p k+1 , the other numbers are still pending, so any one point that cannot be divided by p k+1 can be selected as the current pending point.

[0186] Repeat the expansion process of the prime factorial section until a pending point y in the specified size range is obtained, and finally verify the value of the point to determine whether it is a prime number. Fermat algorithm, Miller-Rabbin algorithm, or other detection methods can be used for verification. If the point value does not meet the requirements, change the value of m to select another point. Generally, in the range of 1 ≤ m ≤ p k+1 , most m values obtained y is a prime number, so the search for prime numbers is effective. If a suitable m value cannot be found in the current prime factorial section, return to the previous prime factorial section. Alternatively, y obtained by selecting any m value in the current prime factorial section can be used directly, because even if y is not a prime number, its factor is very large, and it is already very difficult to solve it, i.e., it is already difficult to solve the key, and it can already be applied to the RSA encryption algorithm.

[0187] If primality detection is performed every time the prime factorial section is expanded, it can better ensure that the obtained large number is a prime number, but the amount of calculation increases a lot, and the effect of doing a few more detections in the last stage is not much different, so no detection is performed every time the prime factorial section is expanded, and only p k+1 is used for quick judgment.

[0188] This method is effective because the growth of prime factorials is very fast, for example, when k = 129, p k = 727, p k=7.2148E+300, so the prime factorial section has a relatively small number of expansions, and large prime numbers can be obtained quickly.

[0189] The process of generating large prime numbers can be used Figure 10 To express it, the steps are as follows:

[0190] 1) Initialize and get the current prime value p k and its position k;

[0191] 2) Set the current pending point x;

[0192] There are two options for steps 1) and 2) above. One is to set the current prime value and the current undetermined point by yourself (i.e., method B). Accordingly, the next prime value p in step 3) k+1 Obtain from the first prime number library, the other is: determine the current prime value and the current undetermined point from the second prime number library (ie method C), accordingly, the next prime value p in step 3) k+1 Get it from the next pending point position.

[0193] If it is the first type, then x=1, k=2, p k =3, that is, starting from the prime number 3 factorial section, of course, you can also start from the prime number 5 factorial section, which can be set arbitrarily. If it is the second type, that is, obtained from the second prime number library, then from the interval A point to be determined is randomly selected as the seed point to be determined x.

[0194] 3) Get the next prime value p k+1 ;

[0195] Let k = k + 1, and get the next prime number p k+1 .

[0196] 4) Randomly select the extension number m;

[0197] Randomly generate an integer m, where 1≤m≤p k+1 .

[0198] 5) Calculate the next undetermined point y;

[0199] According to m, we can calculate y=(m-1)p k !+x.

[0200] 6) Perform divisibility judgment;

[0201] If y can be p k+1 If it is divisible, go to step 4).

[0202] 7) Determine whether the size of point y meets the key generation requirements (can be set according to actual encryption requirements);

[0203] If the size of y meets the large prime size requirement, go to step 9).

[0204] 8) Continue to expand the prime factorial segment;

[0205] Let x = y, p k = p k+1 Go to step 4).

[0206] 9) Detect if it is a composite point;

[0207] Use various detection methods to check if y is a composite number. If it is a composite number, reselect an expansion number m once and calculate y, and go to step 10); otherwise, go directly to step 10).

[0208] The reselection of large primes can be performed multiple times until a number that passes the test is obtained.

[0209] 10) Output the large prime y and end.

[0210] For the sake of simplicity of representation, in the flowchart shown in Figure 10 , p k is represented by p k+1 , and q is represented by q.

[0211] In summary, if the large prime required by the encryption system is within the storage and computing capacity of the computer, the prime is directly obtained according to the algorithm flow shown in Figure 9 ; otherwise, the prime is obtained according to the algorithm flow shown in Figure 10 .

[0212] In order to obtain a large prime, a seed point, i.e., the first x point, must be given first. The seed point can be selected as 1 or 5 from a smaller prime factorial 2x3, or a number can be selected from a larger prime factorial. In order to reduce the amount of calculation for large prime generation, a basic prime library can be constructed using a prime solving algorithm, and the seed can be directly obtained from the basic prime library to speed up the large prime solving process each time the large prime solving is performed. In fact, a certain amount of prime is still required when performing large prime solving, which is the basis for constructing the prime factorial segment, so a basic prime library also needs to be established.

[0213] In order to establish a basic prime library, the solving of primes must be performed first. An array with a size equal to p k ! can be established, and the type of each number can be calculated using a prime solving algorithm. If it is for the purpose of solving a large prime, the prime factorial segment is expanded to p k ! factorial segment, and no screening operation is performed on the data in , so that the data type in only has two types, composite and pending points. If it is for the purpose of obtaining primes within p k !, screening operations must be performed on all data.

[0214] Another advantage of using the basic prime number library is that the variation of the prime numbers obtained is more, because there are many undetermined points in the basic prime number library, and the randomness is better. If the smallest prime number factorial is calculated each time, because of the defects of the random algorithm, it is easy to obtain a large prime number that is relatively close, which is not conducive to security.

[0215] Figure 11 is a prime number solving method diagram for large prime numbers (i.e., a second prime number library establishment flowchart). The method flow is similar to the general prime number solving flow, and the difference is that the purpose of the method is mainly to obtain undetermined points, so after the prime number factorial section is expanded to the maximum block of the system, no further screening operation is performed on the undetermined points.

[0216] The basic prime number library can be divided into two categories: a direct query prime number library (i.e., the first prime number library, also called the basic prime number library) and a prime number seed library (i.e., the second prime number library). The direct query prime number library records all the determined prime numbers in the given number field, and is directly obtained from the prime number library when used. The prime number seed library provides seed undetermined points for large prime number calculation, and records all the undetermined points in the given number field.

[0217] Both databases can use data files or database systems, and because the use is single, it is recommended to use data files, which are simpler and have high query efficiency. Both databases need to record the prime number value p of the current prime number factorial and its position k in the database, so as to be used in the large prime number solving process. k

[0218] The prime number p can be recorded k The type and position of all points in the factorial range, but in order to save storage space, only the prime number value and its position can be recorded in the direct query prime number library, and the composite number value is not recorded. In the prime number seed library, only the undetermined point value in the range of (p k , p1p2…p k -p k ) and its position are recorded, where The undetermined point value in can be used as a prime number value, and the undetermined point value in (p k , p1p2…p k -p k ) is used as a seed value. Because prime numbers are increasingly sparse, this can save a lot of storage space.

[0219] If the range of the large prime number to be solved is in the first prime number library, it is directly obtained by a random method. If the range of the large prime number to be solved is not in the first prime number library, it is calculated and obtained by the method shown in Figure 10

[0220] ​​The embodiment is suitable for solving large prime numbers of various encryption systems. For those skilled in the art, the data structure and algorithm involved in the present application can be implemented in a general computer system, for example, any high-level programming language such as VC++, Java, etc.

[0221] The RSA encryption and decryption system comprises a computer readable storage medium and a processor.

[0222] The computer readable storage medium is used for storing executable instructions.

[0223] The processor is used for reading the executable instructions stored in the computer readable storage medium, and performing the method according to any one of the above embodiments.

[0224] The computer readable storage medium stores computer instructions, and the computer instructions are used for enabling the processor to perform the method according to any one of the above embodiments.

[0225] Those skilled in the art can easily understand that the above description is only the preferred embodiment of the present application, and is not used to limit the present application, and any modification, equivalent replacement and improvement within the spirit and principle of the present application should be included in the protection scope of the present application.

Claims

1. An RSA encryption and decryption method, characterized in that: include: S1, generates two different large prime numbers at the receiving end; S2, the receiving end generates an RSA public key and a private key according to the mutually different large prime numbers, and transmits the RSA public key to the sending end; S3, the sending end encrypts the information to be encrypted using the RSA public key pair to obtain a ciphertext, and sends the ciphertext to the receiving end; S4, the receiving end uses the RSA private key to decrypt the ciphertext to obtain plaintext; The process of generating the large prime number includes: A1, create an array; A2, constructing an initial prime factorial node; wherein the initial prime factorial node is a prime number Factorial section, the prime numbers The factorial node of is a number on the coordinate axis with the origin as the starting point and its size is equal to a prime number Factorial value The interval [0, ), = , are prime numbers arranged in ascending order, and the types of integer points in the interval are prime points, composite points or undetermined points; Set to the current prime number; where, for the initial prime factorial section, ; A3: The first undetermined point on the coordinate axis to the right of the current prime number is used as the prime number. ; A4, determine the current block length and prime number Whether the product of exceeds the limit of the array, if so, go to A8, if not, go to A5; wherein the current block is a storage structure for storing the current prime factorial node; A5, the current prime number The factorial section is the first section, and the first section is copied As a continuation section, so that the type of the midpoint of the obtained continuation section is the same as that of the first section, the first section and each continuation section are sequentially spliced ​​on the coordinate axis to obtain a prime number Factorial Festival; A6, the prime number As the current prime number ; A7, using the current prime number Prime numbers Filter the factorial section: filter the factors in each subsequent section that are smaller than the factors in the first section. The points corresponding to the prime points of are set as composite points, and All in Set the multiple point to the composite point; return to A3; A8, copies and sequentially concatenates the current prime factorial section to fill the array; A9, the prime number As the current prime number ; A10, use the current prime number Filter the concatenated prime factorial sections: All to the end Multiple points are set as composite points; A11, determine whether there is a next undetermined point, if so, make it a prime number And return to A9, if not, end, output all prime numbers as large prime numbers, and place all prime numbers in the first prime number library.

2. The method according to claim 1, wherein The types of integer points in the interval are divided into: 1) Set all numbers not greater than a prime number The prime number of is taken as a known prime number, the point where the known prime number is located is set as a prime point, and 1 is set as a to-be-determined point; 2) Determine whether other integer points in the interval are control points of known prime numbers; If so, set the point as a composite point, otherwise set it as an undetermined point; The control points are endpoints of the control span arcs, and do not include endpoints of the generated span arcs; The generated span arc is to connect the origin of the coordinate axis and the prime point The span arc of the control span arc is the same size as the generated span arc, and the distance between the starting point and the starting point of the generated span arc on the coordinate axis is An integer multiple of .

3. The method according to claim 1, wherein The generation process of the large prime number includes: B1, set the current pending point , the prime number as the current prime number; B2, obtain the next prime value from the first prime number library ; B3, randomly generate extension number , and according to Determine the next pending point in, , ; B4, Judgment Can it be If it is divisible, go to B3, if not, go to B5; B5, judgment point Does the size of meet the preset RSA key generation requirements? If so, go to B6. If not, make , , get the next prime value from the first prime number library , go to B3; B6, judgment point Is it a composite point? If so, go to B3. If not, output y As a large prime number.

4. An RSA encryption and decryption method, characterized in that: include: S1, generates two different large prime numbers at the receiving end; S2, the receiving end generates an RSA public key and a private key according to the mutually different large prime numbers, and transmits the RSA public key to the sending end; S3, the sending end encrypts the information to be encrypted using the RSA public key pair to obtain a ciphertext, and sends the ciphertext to the receiving end; S4, the receiving end uses the RSA private key to decrypt the ciphertext to obtain plaintext; The generation process of the large prime number includes: C1, determine the current prime number in the second prime number library ; C2, in the second prime number library, from the interval Randomly select a pending point as the current pending point ; C3, the first undetermined point on the coordinate axis to the right of the current prime number is taken as the prime number ; C4, randomly generated extension number , and according to Determine the next pending point in, , ; C5, Judgment Can it be If it is divisible, go to C4, if not, go to C6; C6, judgment point Does the size of meet the preset RSA key generation requirements? If so, go to C7. If not, make , , get the next prime value from the second prime number library , go to C4; C7, judgment point Is it a composite point? If so, go to C4. If not, output y As a large prime number; The process of establishing the second prime number library includes: 1) Create an array; 2) Constructing an initial prime factorial node; wherein the initial prime factorial node is a prime number Factorial section, the prime numbers The factorial node of is a number on the coordinate axis with the origin as the starting point and its size is equal to a prime number Factorial value interval , , are prime numbers arranged in ascending order, and the types of integer points in the interval are prime points, composite points or undetermined points; Set to the current prime number; 3) Take the first undetermined point on the coordinate axis to the right of the current prime number as the prime number ; 4) Determine the current block length and prime number Whether the product of exceeds the limit of the array, if so, then end, output the current prime number and all pending points, and place them in the second prime number library; if not, go to 5); wherein the current block is a storage structure for storing the current prime number factorial node; 5) Take the current prime factorial section as the first section and copy the types of each point in the first section As a continuation section, so that the type of the midpoint of the obtained continuation section is the same as that of the first section, the first section and each continuation section are sequentially spliced ​​to obtain a prime number Factorial Festival; 6) Prime numbers As the current prime number ; 7) Use the current prime number Prime numbers Factorial section is filtered: the prime number points corresponding to the first section in each subsequent section are set as composite points, and the All in The multiple points are set as composite points; return to step 3); wherein the prime points corresponding to the first section in each subsequent section do not include the current prime point.

5. An RSA encryption and decryption system, characterized in that: include: Computer-readable storage medium and processor; The computer-readable storage medium is used to store executable instructions; The processor is configured to read the executable instructions stored in the computer-readable storage medium and execute the method according to any one of claims 1 to 4.

6. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the method according to any one of claims 1 to 4 when executed.

Citation Information

Patent Citations

  • RSA key pair fast generation system and RSA key pair fast generation method

    CN106487512A