Pre-prepared food rapid traceability management system based on blockchain
Through symmetric encryption algorithm and random number generator decomposition technology, multi-layer coded traceability codes are generated, which solves the security and low accuracy problems of prepared dish data traceability management in blockchain technology, and achieves more efficient and accurate data storage and Find.
Patent Information
- Application Number
- CN202411074404.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-07
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2044-08-07
AI Technical Summary
Existing blockchain technology has problems of low security and low accuracy in data traceability management of prepared dishes. Especially when using traditional searchable encryption algorithms, key design is difficult and search accuracy is low, resulting in low data storage and search efficiency. .
Use a symmetric encryption algorithm to obtain the first-level ciphertext and first-level key, obtain the second-level key through a random number generator, decompose the mark position, generate a binary code, a positioning code and a sequential code, and further obtain the compression code and traceability verification coefficient, through The combination of these codes generates secondary ciphertext and is stored in the blockchain network to realize the generation and decoding of traceability codes.
It improves the storage security and traceability management accuracy of prepared dish data, avoids the low security issues in traditional searchable encryption algorithms, and enhances data search efficiency and accuracy.
Smart Images

Figure CN118586940B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a blockchain-based rapid traceability management system for prepared dishes. Background Art
[0002] As the production of pre-prepared dishes gradually increases, the relevant data of pre-prepared dishes production also gradually increases. Nowadays, blockchain technology is often combined with food traceability technology to ensure food safety. Blockchain technology has the advantages of decentralization and high security. In the actual application process, in order to facilitate small and micro business owners who cannot build blockchains by themselves and avoid the rapid expansion of data in the blockchain, the alliance chain is often used to store data, reducing the technical cost and storage cost of blockchain traceability technology.
[0003] The data is stored on a third party in the form of a consortium chain. To prevent data leakage from the third party, the technicians will encrypt the data sent to the third party, and use searchable encryption technologies such as trapdoors to ensure that the third party cannot obtain the plain text of the data. At the same time, the encrypted data is searched to speed up data search and ensure data security. However, traditional searchable encryption algorithms have the disadvantages of difficult key design and low search accuracy, resulting in low security and accuracy in the rapid traceability management of pre-prepared food data using blockchain. Summary of the invention
[0004] The present invention provides a blockchain-based pre-prepared food rapid traceability management system to solve the problems of low security and accuracy in the rapid traceability management of pre-prepared food data. The technical solutions adopted are as follows:
[0005] One embodiment of the present invention is a blockchain-based fast traceability management system for prepared dishes, which includes the following modules:
[0006] The data collection module obtains the pre-prepared food data and uses a symmetric encryption algorithm to obtain the primary ciphertext and the primary key of the pre-prepared food data;
[0007] The data encryption module obtains the secondary key of the primary ciphertext, obtains the mark position of the primary ciphertext according to the primary ciphertext of the pre-prepared dish data and the secondary key of the primary ciphertext; obtains the traceability verification coefficient of the mark position according to the mark position of the primary ciphertext and the secondary key; obtains the binary code, binary positioning code, and sequence code of the mark position based on the division result of the primary ciphertext and the mark position of the primary ciphertext; obtains the positioning code of the mark position according to the binary code, binary positioning code, and sequence code of the mark position; obtains the compression code of the mark position according to the positioning code of the mark position and the secondary key of the primary ciphertext; obtains the secondary ciphertext according to the positioning code, compression code, and secondary key of the mark position; obtains the secondary verification code according to the traceability verification coefficient of the mark position;
[0008] The data management module generates a pre-prepared food data storage request based on the acquired secondary ciphertext, and sends the pre-prepared food data storage request to the blockchain network. The blockchain network stores the secondary ciphertext based on the received pre-prepared food data storage request; obtains the traceability code based on the primary key, secondary key, and verification code data sequence, and obtains the corresponding pre-prepared food data based on the traceability code.
[0009] Preferably, the method for obtaining the secondary key of the primary ciphertext and obtaining the marking position of the primary ciphertext according to the primary ciphertext of the prepared dish data and the secondary key of the primary ciphertext is:
[0010] A random number generator is used to obtain a preset number of numbers, a sequence composed of all the numbers is used as the secondary key of the primary ciphertext, the number of data in the secondary key is used as the marking coefficient, and marking data of the marking coefficient in the primary ciphertext is randomly selected, each of the marking data is used as a marking position of the primary ciphertext, a sequence composed of all the marking positions is used as the marking sequence of the primary ciphertext, and the elements in the marking sequence are matched one by one with the elements in the secondary key according to the arrangement order.
[0011] Preferably, the method for obtaining the traceability verification coefficient of the mark position according to the mark position of the primary ciphertext and the secondary key is:
[0012] For each mark position in the mark sequence of the first-level ciphertext, the data in the second-level key corresponding to the mark position is used as the characteristic coefficient, and the characteristic coefficient is converted into a binary number. A characteristic search window with the same string length as the binary number corresponding to the characteristic coefficient is constructed according to the string length of the binary number corresponding to the characteristic coefficient, and the characteristic search window is slid forward and backward alternately from the mark position. The sliding step of the characteristic search window is the same as the string length of the binary number corresponding to the characteristic coefficient. When the data in the characteristic search window is the same as the binary number corresponding to the characteristic coefficient, the number of times the current sliding window slides is recorded, and the number of times the current sliding window slides is used as the traceability verification coefficient of the mark position, and the sequence composed of elements in the current characteristic search window is used as the characteristic search sequence of the mark position.
[0013] Preferably, the method for respectively obtaining the binary code, the binary positioning code, and the sequence code of the mark position based on the division result of the first-level ciphertext and the mark position of the first-level ciphertext is:
[0014] For each mark position in the mark sequence of the first-level ciphertext, a binary search method is used to obtain a division sequence of the first-level ciphertext, and the division sequence of the first-level ciphertext is numbered according to the arrangement order of the first-level ciphertext content, and the number of the division sequence of the first-level ciphertext where the characteristic position is located is used as the binary location code of the characteristic position; the length of the string between the characteristic position and the first character in each division sequence is used as the sequence coefficient of each division sequence, and a sequence composed of sequence coefficients corresponding to all the division sequences sorted according to the encoding order of the corresponding division sequences is used as the sequence code of the characteristic position, and the number of divisions of the current first-level ciphertext is used as the binary code of the characteristic position; the binary discrimination value of the mark position is obtained according to the binary code and the sequence code corresponding to the mark position, and the number of divisions of the first-level ciphertext is determined based on the binary discrimination value.
[0015] Preferably, the method of obtaining the binary discrimination value of the mark position according to the binary code and the sequence code corresponding to the mark position, and determining the number of divisions of the primary ciphertext based on the binary discrimination value is:
[0016] For each mark position in the mark sequence of the first-level ciphertext, convert the sequence code corresponding to the mark position into a binary number, use the string length corresponding to the binary number as the sequence characteristic coefficient of the mark position, and use the sum of the binary code corresponding to the mark position and the sequence characteristic coefficient of the mark position as the binary discriminant value of the mark position;
[0017] The binary discrimination value of the current mark position is compared with the binary discrimination value of the last division mark position, and the number of divisions of the first-level ciphertext is determined according to the comparison result.
[0018] Preferably, the method for obtaining the positioning code of the marking position according to the binary code, the binary positioning code and the sequence code of the marking position is:
[0019] For each mark position in the mark sequence of the first-level ciphertext, the binary code, binary positioning code, and sequence code corresponding to the mark position are converted into binary numbers respectively, and a binary string composed of the binary number of the binary code, the binary number of the binary code positioning code, and the binary number of the sequence code in order is used as the initial positioning code of the mark position, a flag is set before the first character of the initial positioning code, an isolate code is set between the last character of the binary number of the binary code in the initial positioning code and the first character of the binary number of the binary positioning code in the initial positioning code, and the updated result of the initial positioning code is used as the positioning code of the mark position.
[0020] Preferably, the method for obtaining the compression code of the marked position according to the positioning code of the marked position and the secondary key of the primary ciphertext is:
[0021] For each mark position in the mark sequence of the first-level ciphertext, convert the element in the second-level key corresponding to the mark position into a binary number, and use the string length of the binary number as the effective length coefficient of the mark position; construct a first-level compression code of the mark position based on the effective length coefficient, when the effective length coefficient is in a first preset interval, use the effective length coefficient as the string length of the first-level compression code of the mark position, and when the effective length coefficient is in a second and designed interval, use the sum of the effective length coefficient and the first preset parameter as the string length of the first-level compression code of the mark position;
[0022] The character string length of the positioning code corresponding to the marked position is used as the compression coefficient of the marked position, the compression coefficient is converted into a binary number as the target information code of the marked position, and the character string length corresponding to the target information code of the marked position is used as the compression feature coefficient of the marked position. If the character string length of the first-level compression code of the marked position is greater than or equal to the compression feature coefficient of the marked position, the target information code represented by the first-level compression code is used as the first-level compression information code; if the character string length of the first-level compression code of the marked position is less than the compression feature coefficient of the marked position, a second-level compression code is constructed based on the character string length of the first-level compression code, and the construction is stopped until the compression code can completely represent the target information code, and the character string composed of all compressed information codes is used as the compression code of the marked position.
[0023] Preferably, the method for obtaining the secondary ciphertext according to the positioning code, compression code and secondary key of the marking position is:
[0024] For each mark position in the mark sequence of the first-level ciphertext, if the feature search sequence corresponding to the mark position is in front of the mark position, the sequence consisting of the positioning code and the compression code corresponding to the mark position is inserted in front of the first element of the feature search sequence corresponding to the mark position; if the feature search sequence corresponding to the mark position is after the mark position, the sequence consisting of the positioning code and the compression code corresponding to the mark position is inserted after the last element of the feature search sequence corresponding to the mark position;
[0025] The result obtained after inserting the positioning codes and compression codes corresponding to all the tag positions in the tag sequence of the first-level ciphertext is used as the second-level ciphertext.
[0026] Preferably, the method for obtaining the secondary verification code according to the traceability verification coefficient of the marked position is:
[0027] The traceability verification coefficients corresponding to all the mark positions of the primary ciphertext are arranged in the order of the positions of the mark positions in the mark sequence to form a sequence as the secondary verification code.
[0028] Preferably, the method of obtaining the traceability code according to the primary key, the secondary key, and the verification code data sequence, and obtaining the corresponding pre-prepared dish data according to the traceability code is:
[0029] The first-level key, second-level key, and verification code data sequence corresponding to each first-level ciphertext are stored in the form of a traceability code. The corresponding first-level key, second-level key, and verification code data sequence can be obtained according to the traceability code. The corresponding second-level ciphertext can be found in the blockchain network according to the second-level key and the verification code data sequence, and the corresponding first-level ciphertext can be obtained according to the second-level ciphertext. The corresponding pre-prepared dish data can be obtained according to the first-level ciphertext and the first-level key.
[0030] The beneficial effects of the present invention are as follows: the primary ciphertext of the pre-prepared food data is obtained through the AES encryption algorithm, the secondary key is obtained through the random number generator, the tag sequence is obtained according to the primary ciphertext and the secondary key, the binary code, the binary positioning code, the sequence code, and the traceability verification coefficient corresponding to each tag position in the tag sequence are obtained according to the tag sequence and the secondary key, the positioning code corresponding to the tag position is obtained according to the binary code, the binary positioning code, and the sequence code corresponding to the tag position, and the compression code corresponding to the tag position is obtained according to the positioning code corresponding to the tag position and the secondary key. The secondary ciphertext is obtained according to the compression code and the positioning code corresponding to the tag position, and the secondary ciphertext is used as the pre-prepared food storage data. The beneficial effects of the present invention are as follows: the low security problem of the trapdoor technology in the traditional searchable encryption algorithm is avoided, the security of the pre-prepared food data storage is improved, and the management accuracy of the rapid traceability of the pre-prepared food is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0032] Figure 1 A schematic diagram of a process flow of a blockchain-based pre-prepared food rapid traceability management system provided by one embodiment of the present invention;
[0033] Figure 2 A schematic diagram of the composition of a first-level compressed information code provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0034] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0035] See also Figure 1 , which shows a flow chart of a blockchain-based pre-prepared food rapid traceability management system provided by an embodiment of the present invention. The system includes the following modules: a data acquisition module, a data encryption module, and a data management module.
[0036] The data collection module collects relevant data from each link in the pre-prepared food production process, including the location, time, dishes used, cooking methods, etc. of the pre-prepared food production, and uses the relevant data as the original data of the pre-prepared food. The input is the original data of the pre-prepared food, and the AES (Advanced Encryption Standard) encryption algorithm is used to obtain the ciphertext and key of the original data of the pre-prepared food. The ciphertext of the original data of the pre-prepared food is used as the first-level ciphertext, and the key of the original data of the pre-prepared food is used as the first-level key. The first-level ciphertext is stored in binary form.
[0037] At this point, the first-level ciphertext and first-level key of the original data of the pre-prepared dishes have been obtained.
[0038] Data encryption module, using random number generator to obtain A randomly generated hexadecimal number will be A sequence of randomly generated hexadecimal numbers is used as the secondary key of the primary ciphertext, and the number of data in the secondary key is used as the marking coefficient , randomly select the first-level ciphertext Each marked data is used as a marked position of the first-level ciphertext. The sequence of mark positions is used as the mark sequence of the first-level ciphertext, and the elements in the mark sequence are matched one by one with the elements in the second-level key in the order of arrangement. For example, the second-level key is , the tag sequence is , the elements in the tag sequence correspond to the elements in the secondary key in order of arrangement, that is, and correspond, and correspond, and correspond.
[0039] Further, the primary ciphertext of the original data of the prepared dish is encrypted twice according to the tag sequence. Specifically, for the first A mark position is determined in the primary ciphertext of the original data of the prepared dish. The label data corresponding to the label position , using the element in the secondary key corresponding to the tag data as the search key content . The key content will be searched Convert it into a binary string, construct a feature search window with the same length as the string, and add the feature search window from the labeled data Start searching forward and backward alternately, the sliding step of the feature search window is proportional to the search key content The length of the corresponding string is the same as that of the search key content. When the contents of the corresponding character strings are the same, the number of times the current feature search window slides is recorded, and the number of times the current feature search window slides is used as the first Traceability verification coefficient for each marking position , the sequence of elements in the current feature search window is taken as the first Feature search sequence for marker positions .
[0040] Furthermore, the input is the first-level ciphertext of the original data of the prepared dish, and the binary search method is used to obtain the first division result of the first-level ciphertext. Each divided part in the first division result of the first-level ciphertext is used as a division sequence of the first-level ciphertext, and all the division sequences are encoded according to the position of the content in the division sequence in the first-level ciphertext. For example, the first-level ciphertext is , the partition sequence of the first-level ciphertext obtained by binary search is , ,Will , They are numbered 1 and 2 respectively. The specific implementation of the dichotomy is a well-known technology and will not be described in detail.
[0041] Furthermore, the labeled data The number of the partition sequence is used as the binary positioning code of the first partition result of the first-level ciphertext, marking the data The number of bits between the first data in each divided sequence is used as the positioning coefficient of each divided sequence, and the sequence composed of the positioning coefficients of all the divided sequences sorted in the order of the corresponding divided sequence numbers is used as the sequence code of the first division result of the first-level ciphertext, the number of divisions corresponding to the first-level ciphertext is used as the binary code of the first division result of the first-level ciphertext, and the sum of the binary code and the binary positioning code of the first division result of the first-level ciphertext is calculated as the binary discrimination value of the first division result of the first-level ciphertext, so as to obtain the binary code, binary positioning code, sequence code and binary discrimination value corresponding to the first division result of the first-level ciphertext of the original data of the pre-prepared dishes.
[0042] Furthermore, the input is the result of the first division of the first-level ciphertext of the original data of the pre-prepared dish, and the binary method is used to obtain the second division result of the first-level ciphertext of the original data of the pre-prepared dish, and the process of obtaining the binary code, binary positioning code, sequence code, and binary discrimination value of the first division result of the first-level ciphertext of the original data of the pre-prepared dish is the same as that of obtaining the binary code, binary positioning code, sequence code, and binary discrimination value of the second division result of the first-level ciphertext of the original data of the pre-prepared dish; if the binary discrimination value of the second division result of the first-level ciphertext of the original data of the pre-prepared dish is greater than the binary discrimination value of the first division result of the first-level ciphertext of the original data of the pre-prepared dish If the binary discrimination value is less than the binary discrimination value of the second division result of the first-level ciphertext of the original data of the pre-prepared dish, the original data of the pre-prepared dish is divided for the third time. The input of each division iteration of the first-level ciphertext of the pre-prepared dish is the result of the previous division. The output of each division iteration is the binary code, the binary positioning code, the sequence code, and the binary discrimination value. Whether the division iteration is stopped is determined according to the output binary discrimination value. The binary code, the binary positioning code, and the sequence code output by the last division iteration when the division iteration stops are used as the marking data. Binary code, binary positioning code, and sequential code.
[0043] Furthermore, the labeled data The corresponding binary positioning code and sequence code are converted into binary numbers; the marking data The corresponding binary code is used as the binary coefficient, and a binary number with a repetition of 1 is constructed according to the value of the binary coefficient. For example, if the binary coefficient is 3, the binary number corresponding to the constructed binary code is 111; the binary number corresponding to the binary code, the binary number corresponding to the binary positioning code, and the binary number corresponding to the sequence code are sequentially composed of a binary string as the tag data The initial positioning code is set before the first character of the initial positioning code, and the flag is set to 0, indicating that the string is a positioning code; a separator code is set between the last character of the binary number of the binary code in the initial positioning code and the first character of the binary number of the binary positioning code in the initial positioning code, and the update result of the initial positioning code is used as the marking data The positioning code.
[0044] Furthermore, the labeled data The length of the string corresponding to the positioning code is used as the tag data The compression factor is converted into a binary number as the marking data The target information code is used as the tag data. Compression characteristic coefficient ; Mark the data Corresponding feature search sequence The string length is used as the effective length coefficient of the first-level compression code To ensure that the feature search sequence corresponds to a valid compressed information code, when the string length of the compressed information code In the interval When the first-level compression code string length is ; When the length of the string of the compressed information code In the interval When , the string length of the first-level compression code is .
[0045] Furthermore, if Greater than or equal to , it means that the first-level compression code can completely represent the target information code, and the target information code represented by the first-level compression code is used as the first-level compression information code. Specifically, Figure 2 The figure shows the composition diagram of the first-level compressed information code; if Less than , it means that the first-level compression code cannot fully represent the target information code, then a second-level compression code is constructed based on the string length of the first-level compression code, and the string length of the second-level compression code is ,like Greater than or equal to , it means that the secondary compression code can completely represent the target information code, the target information code represented by the secondary compression code is used as the secondary compression information code, and the string length of the secondary compression code is Convert to binary number, and the string length of the second level compression code represented by the first level compression code The converted binary number is used as the first-level compressed information code; if Less than , it means that the secondary compression code cannot fully represent the target information code, then a third-level compression code is constructed based on the string length of the secondary compression code, and the string length of the third-level compression code is ; and so on, until the construction The level-compressed information code can completely represent the target information code.
[0046] Furthermore, in the first-level compressed information code, the second-level compressed information code, ..., A flag is set before the first character of the string corresponding to the first-level compression information code. When the flag is 1, it indicates the first-level compression information code, the second-level compression information code, ..., The character string corresponding to the level compression information code is the compression code.
[0047] Further, the first-level compressed information code, the second-level compressed information code, ..., The level compression information code and positioning code are inserted into the level 1 ciphertext. Specifically, when the feature search sequence In labeling data In front of the The string consisting of the first-level compressed information code, ..., the second-level compressed information code, and the first-level compressed information code is inserted into the feature search sequence In front of; when the feature search sequence In labeling data When the information is behind the first-level compressed information code, the second-level compressed information code, ..., The string consisting of the sequence of level-compressed information code and positioning code is inserted into the feature search sequence behind.
[0048] Furthermore, the above process completes the first The insertion of the corresponding content of the tag position is consistent with the insertion of the first The insertion method of the corresponding content of each mark position is the same. The content corresponding to each element in the mark sequence can be inserted into the first-level ciphertext. It should be noted that the positioning code corresponding to the last element in the mark sequence is inserted at the front of the first-level ciphertext as the search start code.
[0049] At this point, according to the above process, the corresponding content is inserted into the first-level ciphertext to obtain the second-level ciphertext, and the traceability verification coefficients corresponding to each element in the tag sequence are sorted in the order of the positions of the corresponding elements in the tag sequence as the second-level verification code.
[0050] In the data management module, the pre-prepared meal producer uses the secondary ciphertext obtained by processing the pre-prepared meal data through the data encryption module as the pre-prepared meal storage data, generates a pre-prepared meal storage data record transaction request based on the pre-prepared meal storage data, and sends it to the blockchain network; after the blockchain network receives the pre-prepared meal storage data record transaction request, it writes the pre-prepared meal data storage data into the blockchain, thereby completing the pre-prepared meal data storage based on blockchain technology.
[0051] Furthermore, the pre-prepared meal producer places the first-level key, second-level key, and second-level verification code corresponding to the pre-prepared meal data in the product in the form of a traceability code. When consumers need to obtain the traceability information of the pre-prepared meal, they first scan the traceability code to obtain the first-level key, second-level key, and second-level verification code.
[0052] The consumer sends a secondary key and a secondary verification code to a third-party storage platform (blockchain network). The third-party storage platform finds the mark position corresponding to the last element of the mark sequence according to the position information of the search start code of any secondary ciphertext, and obtains the feature search sequence corresponding to the mark position according to the mark position. If the number of slides during the feature search sequence is different from the last digit of the secondary verification code, any secondary ciphertext is not the required pre-prepared dish storage data; if the number of slides during the feature search sequence is the same as the last digit of the secondary verification code, any secondary ciphertext is the required pre-prepared dish storage data; further, the obtained pre-prepared dish storage data is decoded. Specifically, if the feature search sequence is in front of the mark position, the inserted content is in front of the feature search sequence. The positioning code corresponding to the feature search sequence is obtained according to the positional relationship between the inserted content and the feature search sequence. The first level compressed information code, ..., the second level compressed information code, the first level compressed information code, the positioning code corresponding to the characteristic search sequence, The first-level compressed information code, …, the second-level compressed information code, and the first-level compressed information code are deleted; further, the positioning code corresponding to the feature search sequence is used as a new search start code to obtain the mark position corresponding to the second-to-last element in the mark sequence, and the inserted content corresponding to the mark position corresponding to the second-to-last element in the mark sequence is deleted according to the second-level verification code and the search start code; and so on, the inserted content corresponding to each element in the mark sequence is deleted to obtain the first-level ciphertext corresponding to the pre-prepared dish storage data, and the first-level ciphertext is decrypted according to the AES encryption algorithm and the first-level key to obtain the corresponding pre-prepared dish data, and the pre-prepared dish data is displayed to consumers as traceability data. The specific implementation process of the AES encryption algorithm is a well-known technology and will not be repeated here.
[0053] When a third party stores enough data, the secondary ciphertext may be mismatched during the search, causing the third party to search for multiple ciphertexts as suspected primary ciphertexts. At this time, other erroneous search results can be used as obfuscated data to protect user privacy. In addition, there is a random process in the process of calculating the secondary ciphertext through the primary ciphertext, which makes it impossible for consumers to restore the suspected primary ciphertext to the secondary ciphertext through the secondary key, thereby protecting the information security of other users and reducing the risk of data leakage caused by the trapdoor technology in traditional searchable encryption technology during erroneous searches.
[0054] At this point, the rapid traceability management of pre-prepared meals has been completed.
[0055] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modification, equivalent replacement, improvement, etc. made within the principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A blockchain-based fast traceability management system for pre-prepared dishes, characterized by: The system includes the following modules: The data collection module obtains the pre-prepared food data and uses a symmetric encryption algorithm to obtain the primary ciphertext and the primary key of the pre-prepared food data; The data encryption module obtains the secondary key of the primary ciphertext, obtains the mark position of the primary ciphertext according to the primary ciphertext of the prepared dish data and the secondary key of the primary ciphertext; obtains the traceability verification coefficient of the mark position according to the mark position of the primary ciphertext and the secondary key; Based on the division result of the first-level ciphertext and the mark position of the first-level ciphertext, a binary code, a binary positioning code, and a sequence code of the mark position are respectively obtained; Obtain the positioning code of the marked position according to the binary code, binary positioning code and sequence code of the marked position; obtain the compression code of the marked position according to the positioning code of the marked position and the secondary key of the primary ciphertext; obtain the secondary ciphertext according to the positioning code, compression code and secondary key of the marked position; obtain the secondary verification code according to the traceability verification coefficient of the marked position; The data management module generates a pre-prepared food data storage request according to the obtained secondary ciphertext, and sends the pre-prepared food data storage request to the blockchain network. The blockchain network stores the secondary ciphertext according to the received pre-prepared food data storage request; obtains the traceability code according to the primary key, the secondary key, and the verification code data sequence, and obtains the corresponding pre-prepared food data according to the traceability code; The method for obtaining the secondary key of the primary ciphertext and obtaining the marking position of the primary ciphertext according to the primary ciphertext of the prepared dish data and the secondary key of the primary ciphertext is: A random number generator is used to obtain a preset number of numbers, a sequence composed of all the numbers is used as the secondary key of the primary ciphertext, the number of data in the secondary key is used as the marking coefficient, and marking data of the marking coefficient in the primary ciphertext is randomly selected, each of the marking data is used as a marking position of the primary ciphertext, a sequence composed of all the marking positions is used as a marking sequence of the primary ciphertext, and the elements in the marking sequence are matched one by one with the elements in the secondary key according to the arrangement order; The method for obtaining the traceability verification coefficient of the mark position according to the mark position of the primary ciphertext and the secondary key is: For each mark position in the mark sequence of the first-level ciphertext, the data in the second-level key corresponding to the mark position is used as the characteristic coefficient, the characteristic coefficient is converted into a binary number, and a characteristic search window with the same string length as the binary number corresponding to the characteristic coefficient is constructed according to the string length of the binary number corresponding to the characteristic coefficient, and the characteristic search window is alternately slid forward and backward from the mark position, and the sliding step length of the characteristic search window is the same as the string length of the binary number corresponding to the characteristic coefficient. When the data in the characteristic search window is the same as the binary number corresponding to the characteristic coefficient, the number of times the current sliding window slides is recorded, and the number of times the current sliding window slides is used as the traceability verification coefficient of the mark position, and the sequence composed of elements in the current characteristic search window is used as the characteristic search sequence of the mark position; The method for obtaining the positioning code of the marking position according to the binary code, the binary positioning code and the sequence code of the marking position is: For each mark position in the mark sequence of the first-level ciphertext, the binary code, the binary positioning code, and the sequence code corresponding to the mark position are respectively converted into binary numbers, a binary string composed of the binary number of the binary code, the binary number of the binary positioning code, and the binary number of the sequence code in order is used as the initial positioning code of the mark position, a flag is set before the first character of the initial positioning code, an isolation code is set between the last character of the binary number of the binary code in the initial positioning code and the first character of the binary number of the binary positioning code in the initial positioning code, and an updated result of the initial positioning code is used as the positioning code of the mark position; The method for obtaining the secondary ciphertext according to the positioning code, compression code and secondary key of the marking position is: For each mark position in the mark sequence of the first-level ciphertext, if the feature search sequence corresponding to the mark position is in front of the mark position, the sequence consisting of the positioning code and the compression code corresponding to the mark position is inserted in front of the first element of the feature search sequence corresponding to the mark position; if the feature search sequence corresponding to the mark position is after the mark position, the sequence consisting of the positioning code and the compression code corresponding to the mark position is inserted after the last element of the feature search sequence corresponding to the mark position; The result obtained after inserting the positioning codes and compression codes corresponding to all the tag positions in the tag sequence of the first-level ciphertext is used as the second-level ciphertext; The method for obtaining the secondary verification code according to the traceability verification coefficient of the marked position is: The traceability verification coefficients corresponding to all the mark positions of the primary ciphertext are arranged in the order of the positions of the mark positions in the mark sequence to form a sequence as the secondary verification code.
2. The blockchain-based fast traceability management system for prepared dishes according to claim 1 is characterized in that: The method for respectively obtaining the binary code, the binary positioning code, and the sequence code of the mark position based on the division result of the first-level ciphertext and the mark position of the first-level ciphertext is: For each mark position in the mark sequence of the first-level ciphertext, the mark position is used as a characteristic position, and the division sequence of the first-level ciphertext is obtained by using the binary search method. The division sequence of the first-level ciphertext is numbered according to the arrangement order of the first-level ciphertext content, and the number of the division sequence of the first-level ciphertext where the characteristic position is located is used as the binary search positioning code of the characteristic position; the length of the character string between the characteristic position and the first character in each division sequence is used as the sequence coefficient of each division sequence, and the sequence composed of the sequence coefficients corresponding to all the division sequences sorted according to the encoding order of the corresponding division sequences is used as the sequence code of the characteristic position, and the number of divisions of the current first-level ciphertext is used as the binary search code of the characteristic position; the binary search discrimination value of the mark position is obtained according to the binary search code and the sequence code corresponding to the mark position, and the number of divisions of the first-level ciphertext is determined based on the binary search discrimination value.
3. The blockchain-based fast traceability management system for prepared dishes according to claim 2 is characterized in that: The method of obtaining the binary discrimination value of the mark position according to the binary code and the sequence code corresponding to the mark position, and determining the number of divisions of the first-level ciphertext based on the binary discrimination value is: For each mark position in the mark sequence of the first-level ciphertext, convert the sequence code corresponding to the mark position into a binary number, use the string length corresponding to the binary number as the sequence characteristic coefficient of the mark position, and use the sum of the binary code corresponding to the mark position and the sequence characteristic coefficient of the mark position as the binary discriminant value of the mark position; The binary discrimination value of the current mark position is compared with the binary discrimination value of the mark position of the previous division, and the number of divisions of the first-level ciphertext is determined according to the comparison result.
4. The blockchain-based fast traceability management system for prepared dishes according to claim 1 is characterized in that: The method for obtaining the compression code of the marked position according to the positioning code of the marked position and the secondary key of the primary ciphertext is: For each mark position in the mark sequence of the first-level ciphertext, convert the element in the second-level key corresponding to the mark position into a binary number, and use the string length of the binary number as the effective length coefficient of the mark position; construct a first-level compression code of the mark position based on the effective length coefficient, when the effective length coefficient is in a first preset interval, use the effective length coefficient as the string length of the first-level compression code of the mark position, and when the effective length coefficient is in a second preset interval, use the sum of the effective length coefficient and the first preset parameter as the string length of the first-level compression code of the mark position; The character string length of the positioning code corresponding to the marked position is used as the compression coefficient of the marked position, the compression coefficient is converted into a binary number as the target information code of the marked position, and the character string length corresponding to the target information code of the marked position is used as the compression feature coefficient of the marked position. If the character string length of the first-level compression code of the marked position is greater than or equal to the compression feature coefficient of the marked position, the target information code represented by the first-level compression code is used as the first-level compression information code; if the character string length of the first-level compression code of the marked position is less than the compression feature coefficient of the marked position, a second-level compression code is constructed based on the character string length of the first-level compression code, and the construction is stopped until the compression code can completely represent the target information code, and the character string composed of all compressed information codes is used as the compression code of the marked position.
5. The blockchain-based fast traceability management system for prepared dishes according to claim 1 is characterized in that: The method of obtaining the traceability code according to the primary key, the secondary key, and the verification code data sequence, and obtaining the corresponding pre-prepared dish data according to the traceability code is: The first-level key, second-level key, and verification code data sequence corresponding to each first-level ciphertext are stored in the form of a traceability code. The corresponding first-level key, second-level key, and verification code data sequence can be obtained according to the traceability code. The corresponding second-level ciphertext can be found in the blockchain network according to the second-level key and the verification code data sequence, and the corresponding first-level ciphertext can be obtained according to the second-level ciphertext. The corresponding pre-prepared dish data can be obtained according to the first-level ciphertext and the first-level key.
