Operational method for plaintext and ciphertext calculation

Through the Mingcipher Text calculation method, small and medium-sized enterprises encrypt and upload data on the user side and perform suffix expression calculations on the cloud, solving the problems of insufficient computing power and data leakage of small and medium-sized enterprises, and achieving safe and efficient data computing.

CN120498630APending Publication Date: 2025-08-15TONGTAI INFORMATION TECHNOLOGY (XIAN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510615645.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-14
Publication Date
2025-08-15

AI Technical Summary

Technical Problem

Small and medium-sized enterprises lack computing power, plain text calculations may leak, and cipher text calculations require a large amount of data exchange, which increases costs.

Method used

The explicit ciphertext calculation method is adopted, and the user side encrypts the upload data and converts it into a field name mapping. The cloud calculates the suffix expression and decrypts the results. Only the data that needs to be kept confidential is encrypted and calculated through the expression lexer and the suffix expression.

Benefits of technology

Reduces data bandwidth requirements, ensures data security and avoids leakage, and reduces computing costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120498630A_ABST
    Figure CN120498630A_ABST
Patent Text Reader

Abstract

The invention relates to plaintext-ciphertext-packet hybrid operation. An operation method for plaintext and ciphertext calculation comprises the steps that encryption uploading of a user side, cloud calculation and result obtaining and decryption of the user side are carried out, and encryption uploading comprises the steps that data are arranged into a data table, and the data table is converted into a field name mapping (Calculation Token) list; converting the infix expression into a lexical element array through an expression lexical analyzer, and uploading the lexical element array to a cloud end; the cloud computing comprises the steps of firstly converting an infix expression into a lexical array of a suffix expression, then carrying out traversal computing on data dataList by using the lexical array of the suffix expression, and carrying out one-time traversal to obtain Maplt in the dataList; the method comprises the following steps of: carrying out sampling, String, Calculation Tokent; performing calculation; finally, the result is popped out and put into a result list to complete calculation; the cloud computing result is transmitted back to the user side, and the user side decrypts to obtain the computing result. According to the invention, only the data which really needs to be confidential is encrypted, so that the data cannot be leaked, the required data bandwidth is greatly reduced, and the cost is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to encryption operations, and in particular to a method for computing homomorphically encrypted secret data. Background Art

[0002] For many small and medium-sized enterprises, data processing power and confidentiality are two major challenges. Often, these enterprises lack sufficient computing power and are forced to rely on public computing providers. This presents two problems: using plaintext for data calculations can lead to data leaks, while encrypted calculations require more data exchange with computing providers, which consumes significant bandwidth and increases costs for the enterprise.

[0003] On the other hand, there is currently a lack of homomorphic ciphertext calculation methods that cannot support both ciphertext and plaintext operations. It is necessary to make the mixed calculation of plaintext and ciphertext also support expression operations. Summary of the Invention

[0004] The present invention aims to address the above-mentioned shortcomings of the prior art and provides a method for calculating plaintext and ciphertext. The present invention encrypts only the data that truly needs to be kept confidential, ensuring that the data will not be leaked, and also greatly reduces the required data bandwidth and reduces costs.

[0005] The present invention is implemented as follows: a method for calculating plaintext and ciphertext, which includes uploading encrypted data on the user side, computing data on the cloud, and obtaining and decrypting the results on the user side.

[0006] The encrypted upload includes: organizing the data into a data table, converting the data table into a list of field name mappings (CalculationToken); converting the infix expression into a word array through an expression lexical analyzer and uploading it to the cloud;

[0007] Cloud computing includes first converting the infix expression into a word array of a postfix expression, and then traversing the word array of the postfix expression to calculate the data dataList, and obtaining the Map in the dataList in one traversal.<String,CalculationToken> Perform calculations; pop the final result out of the stack and put it into the result list to complete the calculation;

[0008] The cloud computing results are transmitted back to the user end, and the user end decrypts them to obtain the calculation results.

[0009] The method for calculating the plaintext and ciphertext, wherein the expression lexical analyzer converts the infix expression into a word element array, includes:

[0010] 1) Whitespace character filtering: skip consecutive whitespace characters at the current position;

[0011] 2) Token type determination and generation include triggering different parsing logic based on the current character type:

[0012] A. Numbers or decimal points include:

[0013] Implicit multiplication check: If the previous token is a number, an implicit multiplication sign is generated;

[0014] Number parsing: call parseNumberToken to process integers or floating-point numbers;

[0015] B. Delimiters include commas or Chinese delimiters:

[0016] Parameter separator: call parseArgumentSeparatorToken to generate a separator Token;

[0017] C. Brackets:

[0018] Implicit multiplication processing: If there is a number or variable before the left bracket, insert a multiplication token;

[0019] Bracket type token: distinguish between open and closed brackets through parseParenthesesToken(true / false);

[0020] D. Operator: Legality check: Filter illegal symbols through OperatorToken.isAllowedOperator and generate operator Token;

[0021] E. Variable or function names, starting with a letter or underscore:

[0022] Implicit multiplication processing: if it is preceded by a number or bracket, insert a multiplication sign;

[0023] Name resolution: Call parseFunctionOrVariableToken to distinguish functions from variables.

[0024] In the aforementioned method for calculating plaintext and ciphertext, the process of converting the infix expression into a postfix expression includes:

[0025] 1) Initialize the stack and output area

[0026] Create an empty stack (to store operators / parentheses)

[0027] Initialize a string or list (to store the final suffix expression)

[0028] 2) Traverse the infix expression characters

[0029] Operands are added directly to the output area (such as numbers or variables);

[0030] Left bracket (pushed onto the stack;

[0031] Right bracket) pops the top element of the stack to the output area until a left bracket is encountered, which is then popped but not output;

[0032] Operator:

[0033] If the stack is empty or the top of the stack is a left bracket, push it directly into the stack;

[0034] Otherwise, compare the current operator with the top operator of the stack (operator priority: generally defined as * / %>+->(, parentheses have the lowest priority):

[0035] Priority is higher than the top of the stack: push into the stack;

[0036] Priority is equal to or lower than the top of the stack: pop the top of the stack to the output area, and repeat the comparison until it can be pushed onto the stack.

[0037] 3) Processing the rest operator

[0038] After the traversal is completed, all remaining operators in the stack are popped into the output area in sequence;

[0039] Taking the infix expression 9+(3-1)*3+10 / 2 as an example, the conversion process is as follows:

[0040]

[0041] The final suffix expression is: 931-3*+102 / + (space separated).

[0042] The above method uses the word element array of the suffix expression to traverse the data dataList and obtain the Map in the dataList in one traversal.<String,CalculationToken> The calculation process is as follows:

[0043] 1) Build a storage stack output

[0044] 2) Traverse the suffix expression token array, for:

[0045] Digital tokens convert numbers into calculation tokens whose encryption identifiers are plain text and directly put them into the stack;

[0046] Variable tokens, directly get the calculation token CalculationToken from the Map according to the variable name and put it into the stack;

[0047] Operator tokens first check whether the number in the stack meets the calculation requirements. The check condition is that the number of the operator operand is not greater than the stack size. If it meets the requirements, the operator continues to judge whether the operator operand is a binary operation or a unary operation, and further calls the binary operation method of the calculation token or the binary operation method of the calculation token to perform the calculation. The result token is pushed into the stack;

[0048] Function tokens pop the parameters one by one into a list, call the function method of the calculation token to perform calculations, call the corresponding function according to the function name of the function token to perform calculations, and push the calculation results into the stack;

[0049] 3) The final result is popped off the stack and placed into the result list to complete the calculation.

[0050] The present invention abstractly designs operation symbols, plaintext and ciphertext that need to be calculated, and functions, unifies them into word elements and then classifies them for processing, encrypts the data that really needs to be kept confidential, ensures that the data will not be leaked, and greatly reduces the required data bandwidth and reduces costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] The present invention will be further described below in conjunction with the accompanying drawings:

[0052] Figure 1 It is a schematic diagram of the computing flow of the cloud server. DETAILED DESCRIPTION

[0053] See Figure 1 A method for calculating plaintext and ciphertext includes encrypting and uploading data on the user end 1, computing on the cloud 2, and obtaining and decrypting the result on the user end. The encrypted uploading includes: arranging the data into a data table, converting the data table into a list of field name mappings (CalculationToken); converting the infix expression into a word element array through an expression lexical analyzer and uploading it to the cloud; the cloud computing includes first converting the infix expression into a word element array of a postfix expression, and then traversing and calculating the word element array of the postfix expression on the data dataList, and obtaining the Map in the dataList in one traversal.<String,CalculationToken> Perform calculations; the final result is popped off the stack and placed in the result list to complete the calculation; the cloud-based calculation result is transmitted back to the user end, and the user end decrypts it to obtain the calculation result.

[0054] Glossary:

[0055] CalculationToken

[0056]

[0057]

[0058] Token

[0059] variable name meaning type Type of lemma

[0060] The token abstract class is the most basic unit of computation. It contains a single integer variable, type, which is used to classify tokens. The tokens below are all implementations of this abstract class.

[0061] Separator token - ArgumentSeparatorToken

[0062] variable name meaning type Type of lemma ;

[0063] FunctionToken

[0064] variable name meaning type Type of lemma name Function Name argsNum Number of parameters description Function Description ;

[0065] NumberToken

[0066] variable name meaning type Type of lemma value Specific values ;

[0067] Operator Token

[0068]

[0069]

[0070] ParenthesesOpenToken

[0071] variable name meaning type Type of lemma ;

[0072] ParenthesesCloseToken

[0073] variable name meaning type Type of lemma .

[0074] Function abstract class - Function

[0075] By implementing this abstract class, you can complete the function extensions other than the four arithmetic operations, such as trigonometric functions, mean, absolute value, power operations, customized functions, etc. public interface Function {CalculationToken execute(List <calculationtoken>cts,String pubParam)} The implementation process of the execute method first checks whether the number of the incoming calculation word list is the same as the number of input parameters required by the function. If they are the same, the program will continue to execute to further determine the encryption identifier of the calculation dimension, and select the corresponding function for calculation according to the encryption identifier. For example, if the trigonometric function is calculated, the list length of cts is 1. If the encryption identifier of the calculation word is homomorphic encryption, the trigonometric function operation of the homomorphic ciphertext is called, and pubParam is the public parameter used for the ciphertext operation. The binary operation method of the calculation word (addition, subtraction, multiplication, and division) is calculated; the calculation strategy is determined based on the encryption identifiers of the two incoming calculation words to determine whether to call the ciphertext calculation. As long as the encryption identifier type of one calculation word is homomorphic encryption, the homomorphic binary operation method is called, otherwise the plaintext binary operation method is called to calculate the unary operation method of the word (trigonometric function, summation, mean, etc., functions with 1 variable number).

[0076] The calculation strategy is determined based on the encryption identifier of the incoming calculation word to determine whether to call ciphertext calculation. If the encryption identifier type of the calculation word is homomorphic encryption, the homomorphic unary operation method is called, otherwise the plaintext unary operation method is called.

[0077] Overall process

[0078] You need to perform a corresponding formula calculation on a table with a header, such as calculating (x×0.5+y×1.9)÷(z-2). The data of the three variables x, y, and z come from the following table, and are all homomorphically encrypted ciphertext. Convert the following data table into a list of field name mapping CalculationToken. <Map<String,CalculationToken> >dataList).

[0079] x y z 3242 2452 5 2123 4565 7 .

[0080] Convert the infix expression into a token array using the expression lexical analyzer

[0081] Whitespace filtering

[0082] Behavior: Skip consecutive whitespace characters (such as spaces and tabs) at the current position.

[0083] Implementation: Move the pointer pos through the while(Character.isWhitespace(curCh)) loop until a non-whitespace character is encountered.

[0084] Word type judgment and generation

[0085] Trigger different parsing logic according to the current character type:

[0086] Digit or decimal point (Character.isDigit(curCh) || curCh == '.'):

[0087] Implicit multiplication check: If the previous token is a number (e.g., 2(3) needs to be converted to 2*(3)), an implicit multiplication token is generated (buildMultipartToken).

[0088] Number parsing: Call parseNumberToken to process integers or floating-point numbers (such as 3.14).

[0089] Separator (, or Chinese separator):

[0090] Parameter separator: Call parseArgumentSeparatorToken to generate a separator Token, which is often used for function parameters (such as sin(π,0.5)).

[0091] brackets(()[]{}):

[0092] Implicit multiplication processing: If the left bracket is preceded by a number or variable (such as 2[3]), insert a multiplication token.

[0093] Parentheses type token: distinguish between open and closed parentheses via parseParenthesesToken(true / false).

[0094] Operators (+-* / % etc.):

[0095] Validity check: Filter illegal symbols through OperatorToken.isAllowedOperator and generate an operator token.

[0096] Variable or function name (starting with a letter or underscore):

[0097] Implicit multiplication processing: If preceded by a number or brackets (such as 2x), insert a multiplication sign.

[0098] Name resolution: Call parseFunctionOrVariableToken to distinguish between functions (such as sqrt) and variables (such as x).

[0099] Exception handling and robustness

[0100] Illegal character error: If the character cannot match any word type (such as #, $),

[0101] Call BackendException.throwException to throw an exception with location information.

[0102] Implicit logic support: intelligently inserts multiplication signs through judgeLastTokenNeedImplicitMultiplication, improving expression flexibility (for example, 3(x+1) is automatically converted to 3*(x+1)).

[0103] State-driven parsing: This invention uses lastToken to record the previous parsing result, implementing context-sensitive logic (such as implicit multiplication). Layered processing strategy: Separates the parsing logic for different token types into independent methods (such as parseNumberToken and parseOperatorToken) to improve maintainability. Position tracking: The pos variable is used to accurately locate the location of errors, facilitating debugging and error notification.

[0104] Example:

[0105] Assuming the input expression is "2x+sin(π,0.5)", the parsing process is as follows:

[0106] 1. Analysis 2 → Digital Token

[0107] 2. Implicit multiplication logic inserts *→ operator Token

[0108] 3. Parse x → variable Token

[0109] 4. Parsing the +→ operator token

[0110] 5. Parsing sin → function token

[0111] 6. Parsing (→ Left bracket Token

[0112] 7. Parsing π → Constant Token

[0113] 8. Parsing, → Separator Token

[0114] 9. Parsing 0.5 → Digital Token

[0115] 10. Parsing) → Right bracket Token

[0116] Provides basic lexical analysis capabilities for compilers, formula calculators, and other scenarios, and supports structured processing of complex expressions.

[0117] The token array obtained by the above process is still an infix expression, which is converted into a token array of a postfix expression through the following process.

[0118] 1) Initialize the stack and output area

[0119] Create an empty stack (to store operator tokens / bracket tokens)

[0120] Initialize a token array as the output area (to store the final suffix expression)

[0121] 2) Traverse the infix expression tokens

[0122] Operands are added directly to the output area (such as digital tokens or variable tokens);

[0123] Left bracket Token (pushed onto the stack;

[0124] Right bracket Token) pops the top element of the stack to the output area until a left bracket is encountered. The left bracket is popped but not output; when the operator Token is encountered:

[0125] If the stack is empty or the top of the stack is a left bracket, push it directly into the stack;

[0126] Otherwise, compare the priority of the current operator Token with the top operator Token on the stack (operator priority: generally defined as * / %>+->(, brackets have the lowest priority):

[0127] Priority is higher than the top of the stack: push into the stack;

[0128] Priority is equal to or lower than the top of the stack: pop the top of the stack to the output area, and repeat the comparison until it can be pushed onto the stack.

[0129] 3) Processing the rest operator

[0130] After the traversal is completed, all remaining operator tokens in the stack are popped into the output area in sequence to obtain the token array of the suffix expression.

[0131] 4. Finally, use the word array of the suffix expression to traverse and calculate the data dataList, and obtain the Map in dataList in one traversal<String,CalculationToken> The calculation process is as follows

[0132] 1) Build a storage stack output

[0133] 2) Traverse the suffix expression token array

[0134] Digital tokens convert numbers into calculation tokens whose encryption identifiers are plain text and directly put them into the stack;

[0135] Variable tokens directly obtain the calculation token CalculationToken from the Map according to the variable name and put it into the stack.

[0136] Operator word, first check whether the number in the stack meets the calculation requirements. The check condition is that the operator operand is not greater than the stack size. If it meets the requirements, continue to judge whether the operator operand (for example, the operand of addition is 2, indicating 2 input parameters) is a binary operation or a unary operation, and further call the binary operation method of the calculation word or the binary operation method of the calculation word to perform calculation, and the result word after calculation is pushed into the stack.

[0137] Function tokens pop the parameters one by one into a list, call the function method of the calculation token to perform calculations, call the corresponding function according to the function name of the function token to perform calculations, and push the calculation results into the stack.

[0138] The final result is popped off the stack and placed into the result list to complete the calculation.< / calculationtoken>

Claims

1. A method for calculating plaintext and ciphertext, comprising uploading encrypted data on the user side, performing cloud computing, and obtaining and decrypting the results on the user side, characterized in that: The encrypted upload includes: organizing the data into a data table, converting the data table into a list of field name mappings (CalculationToken); converting the infix expression into a word array through an expression lexical analyzer and uploading it to the cloud; Cloud computing includes first converting the infix expression into a word array of a postfix expression, and then traversing the word array of the postfix expression to calculate the data dataList, and obtaining the Map in the dataList in one traversal.<String,CalculationToken> Perform calculations; pop the final result out of the stack and put it into the result list to complete the calculation; The cloud computing results are transmitted back to the user end, and the user end decrypts them to obtain the calculation results.

2. The method for calculating plaintext and ciphertext according to claim 1, wherein: The expression lexical analyzer converts the infix expression into a token array including: 1) Whitespace character filtering: skip consecutive whitespace characters at the current position; 2) Token type determination and generation include triggering different parsing logic based on the current character type: A. Numbers or decimal points include: Implicit multiplication check: If the previous token is a number, an implicit multiplication sign is generated; Number parsing: call parseNumberToken to process integers or floating-point numbers; B. Delimiters include commas or Chinese delimiters: Parameter separator: call parseArgumentSeparatorToken to generate a separator Token; C. Brackets: Implicit multiplication processing: If there is a number or variable before the left bracket, insert a multiplication token; Bracket type token: distinguish between open and closed by parseParenthesesToken(true / false) brackets; D. Operator: Legality check: Filter illegal symbols through OperatorToken.isAllowedOperator and generate operator Token; E. Variable or function names, starting with a letter or underscore: Implicit multiplication processing: if it is preceded by a number or bracket, a multiplication sign is inserted; Name resolution: Call parseFunctionOrVariableToken to distinguish functions from variables.

3. The method for calculating plaintext and ciphertext according to claim 1, wherein: The process of converting the infix expression into the postfix expression includes: 1) initializing the stack and the output area Create an empty stack (to store operators / parentheses) Initialize a string or list (to store the final suffix expression) 2) Traverse the infix expression characters Operands are added directly to the output area (such as numbers or variables); Left bracket (pushed onto the stack; Right bracket) pops the top element of the stack to the output area until a left bracket is encountered, which is then popped but not output; Operator: If the stack is empty or the top of the stack is a left bracket, push it directly into the stack; Otherwise, compare the current operator with the top operator priority on the stack (operator priority: generally defined as * / %>+->(, parentheses have the lowest priority): Priority is higher than the top of the stack: push into the stack; Priority is equal to or lower than the top of the stack: pop the top of the stack to the output area, and repeat the comparison until it can be pushed onto the stack. 3) Processing the rest operator After the traversal is completed, all remaining operators in the stack are popped into the output area one by one.

4. The method for calculating plaintext and ciphertext according to claim 1, wherein: Use the word array of the suffix expression to traverse and calculate the data dataList, and obtain the Map in dataList in one traversal<String,CalculationToken> The calculation process is as follows: 1) Build a storage stack output 2) Traverse the suffix expression word array, for Digital tokens convert numbers into calculation tokens whose encryption identifiers are plain text and directly put them into the stack; Variable token, directly get the calculation token CalculationToken from the Map according to the variable name, Put it on the stack Operator word, first check whether the number in the stack meets the calculation requirements. The check condition is that the operator operand is not greater than the stack size. If it meets the requirements, continue to judge whether the operator operand is a binary operation or a unary operation, and further call the binary operation method of the calculation word or the binary operation method of the calculation word to perform calculation, and the result word after calculation is pushed into the stack. Function tokens pop the parameters one by one into a list, call the function method of the calculation token to perform calculations, call the corresponding function according to the function name of the function token to perform calculations, and push the calculation results into the stack; 3) The final result is popped off the stack and placed into the result list to complete the calculation.