A blockchain-based animal lifecycle traceability method

CN122679243APending Publication Date: 2026-09-01SUZHOU YAOSHU TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610866002.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-06-16
Publication Date
2026-09-01

AI Technical Summary

Technical Problem

[0008]本申请提供一种基于区块链的动物全生命周期溯源方法、系统、设备及存储介质,以解决在区块链数据加密过程中私钥可预测性高的技术问题

Benefits of technology

[0042]The technical solution provided in this application firstly involves performing complexity screening on a single original animal image to determine the selected animal image. This increases the basic complexity of the selected animal image, thereby reducing its predictability and effectively avoiding the problem of an overly simple generated key due to insufficient image complexity, thus improving the unpredictability of the generated key. Secondly, the selected animal image is scrambled and compressed before encoding. Scrambling increases the randomness of run-length compression coding, while compression reduces its repetitiveness, thereby reducing the predictability of run-length compression coding and increasing its complexity. Then, a truncation-priority key-value pair is generated based on random numbers. The sequence is used to determine the final combined code, improving the randomness of the run-length compression coding combination process and reducing the predictability of the final combined code. Furthermore, using the truncation-priority key-value pair sequence to partially truncate and randomly combine the run-length compression code can avoid the problem of key leakage due to the leakage of a single screened animal image, further improving the security of the key. Finally, the animal traceability private key and animal traceability public key generated from the screened animal images are used to decrypt, read, and encrypt the animal's entire life cycle traceability data, reducing the predictability of the private key source and effectively avoiding blockchain data security problems caused by blockchain private key prediction, thus improving the security of blockchain data encryption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122679243A_ABST
    Figure CN122679243A_ABST
Patent Text Reader

Abstract

This application provides a blockchain-based method for tracing the entire lifecycle of animals. It receives animal lifecycle tracing data and a set of original animal images. The method performs complexity filtering on each individual original animal image in the set to determine a filtered set of animal images. A random scrambling matrix set is generated. Each filtered animal image in the set is scrambled and compressed according to the random scrambling matrix set before encoding, thus determining a run-length compression encoding set. A truncation-priority key-value pair sequence is determined based on the run-length compression encoding set. A set of encoding fragments to be concatenated is determined based on the truncation-priority key-value pair sequence and the run-length compression encoding set, thus determining the final combined encoding. An animal tracing private key and a public key are determined based on the final combined encoding. The animal lifecycle tracing data is decrypted, read, and encrypted using the animal tracing private key and public key, reducing the predictability of the private key's origin and thus improving the security of blockchain data encryption.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of blockchain technology, and in particular to a blockchain-based method for tracing the entire life cycle of animals. Background Technology

[0002] Animal lifecycle traceability refers to the complete recording and tracking of information such as an animal's identity, health status, medication records, and feed source throughout all stages from birth, breeding, quarantine, slaughter, transportation to sales. Traditional traceability systems often rely on centralized databases or paper-based records, which present the following prominent problems: In a centralized storage model, insiders or hackers can illegally modify historical records, making traceability information unreliable.

[0003] Data from each link (farm, quarantine station, slaughterhouse, logistics company) is not interconnected, making it difficult for consumers to verify the complete chain.

[0004] If sensitive information such as farmers' precise geographical location and contact information is made public, it may be used maliciously.

[0005] Although some blockchain traceability solutions use encryption protection, the generation of private keys relies on fixed random numbers or simple user input, which makes them highly predictable. Once the key is leaked, the authenticity of the entire traceability chain will collapse.

[0006] Blockchain technology, due to its decentralized and immutable characteristics, is widely considered an ideal solution to the trust problem in traceability. However, existing blockchain-based animal traceability systems primarily focus on data storage on the chain, neglecting the security of key generation. A common practice is to use random number generators or user-defined strings to generate public and private keys. However, random number generators have reusability risks, and user-defined strings are vulnerable to brute-force attacks, resulting in highly predictable private keys. Once an attacker guesses the private key, they can forge or tamper with the data on the chain, causing the traceability system to lose its credibility.

[0007] Therefore, a key generation method that can reduce the predictability of private keys is needed and applied to the animal life cycle traceability scenario to protect the privacy of sensitive information and prevent the keys from being maliciously predicted while ensuring the immutability of data. Summary of the Invention

[0008] This application provides a blockchain-based method, system, device, and storage medium for tracing the entire life cycle of animals, in order to solve the technical problem of high predictability of private keys during blockchain data encryption.

[0009] To solve the above-mentioned technical problems, this application adopts the following technical solution: Firstly, this application provides a blockchain-based method for tracing the entire life cycle of animals, comprising the following steps: Receive animal life cycle traceability data and a set of original animal images, perform complexity filtering on each individual original animal image in the set of original animal images, determine the set of filtered animal images and the total number of filtered images in the set of filtered animal images, and generate a set of random scrambling matrices based on the total number of filtered images; The random scrambling matrix set is used to scramble each individual animal image in the selected animal image set to determine the scrambled animal image set. Each individual scrambled animal image in the scrambled animal image set is then compressed to determine the run-length compression code for each individual scrambled animal image, thereby determining the run-length compression code set. Obtain the number of bits for each run-length compressed code in the run-length compressed code set, determine the binary length set of each code, and determine the truncation-priority key-value pair sequence based on the binary length set of each code; The set of coded segments to be spliced ​​is determined based on the truncation-priority key-value pair sequence and the run-length compression code set; the final combined code is determined based on the truncation-priority key-value pair sequence and the set of coded segments to be spliced; and the animal traceability private key and animal traceability public key are determined based on the final combined code. The animal's entire life cycle traceability data is encrypted and stored using the animal traceability public key, and decrypted and read using the animal traceability private key.

[0010] In some embodiments, performing complexity filtering on each individual original animal image in the original animal image set to determine the filtered animal image set and the total number of filtered images in the filtered animal image set specifically includes: For each individual original animal image in the set of original animal images, determine the image content complexity of the individual original animal image; A single original animal image whose image content complexity exceeds the acceptable threshold is used as a single filtered animal image, thereby determining the set of filtered animal images. The order of magnitude of the filtered animal image set is taken as the total number of images filtered.

[0011] In some embodiments, determining the image content complexity of the single original animal image specifically includes: Determine the pixel transformation matrix of the original image based on a single original animal image; The pixel distribution uniformity of a single animal original image is determined based on the original image pixel transformation matrix; Set the range for the uniformity of animal image feature dispersion; The image content complexity of a single animal original image is determined based on the pixel distribution uniformity and the range of animal image feature dispersion uniformity.

[0012] In some embodiments, determining the pixel distribution uniformity of a single original animal image based on the original image pixel transformation matrix specifically includes: Determine the pixel contrast factor of the pixel transformation matrix of the original image; Obtain the grayscale levels of pixels in a single original animal image; Determine the difference between adjacent gray levels in the original image pixel transformation matrix; The dispersion of the gray level in the pixel transformation matrix of the original image is determined based on the difference between the adjacent gray levels and the gray level. The pixel distribution uniformity of a single animal original image is determined based on the pixel contrast factor of the original image pixel transformation matrix, the gray level of the pixels in the single animal original image, the difference between adjacent gray levels, and the dispersion of adjacent gray levels.

[0013] Specifically, the pixel distribution uniformity of the single original animal image is calculated using the following steps: The first step is to obtain the total number of rows and columns of the original image pixel transformation matrix, and then multiply the two to get the total number of elements.

[0014] The second step involves performing the following sub-steps sequentially for each element in the original image pixel transformation matrix: Get the pixel contrast factor corresponding to the element; Obtain the gray levels of the starting and ending points during pixel traversal of a single animal original image, and calculate the sum of these two gray levels; Obtain the difference between adjacent gray levels at the starting point and the difference between adjacent gray levels at the ending point, and calculate the sum of these two differences. Divide the sum of the gray levels at the starting point and the ending point by the sum of the two differences mentioned above to obtain the first ratio; Obtain the dispersion of adjacent gray levels at the starting point gray level and the dispersion of adjacent gray levels at the ending point gray level, calculate the sum of these two dispersions, and then divide by two to obtain the second ratio. Multiply the pixel contrast factor, the first ratio, and the second ratio to obtain a temporary result for the element.

[0015] The third step is to sum up the temporary results of all elements to obtain a total sum.

[0016] The fourth step is to divide the accumulated sum by the total number of elements, and the resulting quotient is the pixel distribution uniformity of the original image of the single animal.

[0017] The calculation method for the difference between adjacent gray levels is as follows: multiply the gray level by the reciprocal of the pixel contrast factor, and then multiply by an exponential function value with the natural constant as the base and the gray level as the exponent. The calculation method for the dispersion of adjacent gray levels is as follows: multiply the difference between adjacent gray levels by the gray level, and then multiply by an exponential function value with the natural constant as the base and the negative difference between the adjacent gray levels as the exponent.

[0018] It should be noted that the original image pixel transformation matrix is ​​generated as follows: All pixels in a single original animal image are arranged in a matrix according to their positions. The grayscale value of each pixel is used as the value of each row and column in this matrix arrangement to generate a key source pixel matrix. All unique grayscale values ​​in the key source pixel matrix are counted, and all unique grayscale values ​​are mapped to different grayscale levels according to their magnitude. The set of all grayscale levels is taken as the grayscale level set. Any point in the single original animal image is selected as the starting point, and the point after a transformation with a fixed direction and distance from the starting point is taken as the ending point. The starting point and the ending point constitute a grayscale value pair. Traverse all pixels in the key source image to determine all possible grayscale value pairs, and take the set of all grayscale value pairs as the grayscale value pair set. In the grayscale level set, obtain the grayscale level of each starting point and the grayscale level of each ending point in the grayscale value pair set. Use the grayscale level of the starting point as the row index and the grayscale level of the ending point as the column index. Count the number of times the process of transforming from the grayscale level of the starting point to the grayscale level of the ending point occurs, and use this number as the element value of the corresponding position in the pixel transformation matrix of the original image, thereby generating the pixel transformation matrix of the original image.

[0019] In some embodiments, each individual selected animal image in the selected animal image set is scrambled according to the random scrambling matrix set, thereby determining the scrambled animal image set, specifically including: For each individual random scrambling matrix in the set of random scrambling matrices, the corresponding single filtered animal image is converted into an animal image matrix block according to the single random scrambling matrix; an animal image grayscale matrix block is determined according to the animal image matrix block; the animal image grayscale matrix block is scrambled according to the single random scrambling matrix to determine the scrambled grayscale matrix block; and the scrambled grayscale matrix block is converted into a single scrambled animal image.

[0020] In specific implementation, the single filtered animal image is segmented into animal image matrix blocks with the same number of rows and columns as the single random scrambling matrix; the grayscale value of each element in the animal image matrix block is obtained, and these grayscale values ​​are sequentially read into an empty matrix, which is the animal image grayscale matrix block; each element value in the animal image grayscale matrix block is XORed with the corresponding element value in the single random scrambling matrix to scramble the grayscale values, and the result of the XOR operation is used as the grayscale scrambling result matrix; all grayscale column vectors are extracted from the grayscale scrambling result matrix using a diagonal traversal method, and all scrambled matrix column vectors are extracted from the single random scrambling matrix using the same diagonal traversal method; the elements in each scrambled matrix column vector are sorted by size, and the elements in the corresponding grayscale column vectors are rearranged in the same order according to the sorting result; all rearranged grayscale column vectors are recombined to obtain the scrambled grayscale matrix block.

[0021] In some embodiments, each individual scrambled animal image in the scrambled animal image set is compressed, and the run-length compression code for each individual scrambled animal image is determined, thereby determining the run-length compression code set, specifically including: For each individual scrambled animal image in the scrambled animal image set, the individual scrambled animal image is converted into a color model of the scrambled image; the color model of the scrambled image is subjected to component conversion processing to determine the frequency domain feature values; the frequency domain feature values ​​are subjected to discrete level mapping to obtain a discrete level mapping matrix, and then a zigzag traversal array is determined; the run-length compression code of the individual scrambled animal image is determined according to the zigzag traversal array.

[0022] In practice, each scrambled animal image is divided into multiple matrix blocks. Image model conversion methods from existing image processing libraries are used to convert each matrix block into a brightness and color-separated image model, where color separation results in blue and red chromaticity. A frequency domain feature value range is pre-defined as a discrete level. The frequency domain feature value of each pixel is mapped to a specific level within this discrete level, generating a discrete level mapping matrix. The rows of this matrix represent the original values ​​of the frequency domain feature values, and the columns represent the corresponding discrete levels. The discrete level mapping matrix is ​​read using a zigzag traversal method, and all read results are sequentially arranged into a zigzag traversal array. The values ​​that appear consecutively in this array and their repetition counts are counted. These repetition counts and their corresponding repetition values ​​are then arranged sequentially to form a run-length compression code.

[0023] In some embodiments, the color model of the scrambled image is subjected to component conversion processing to determine frequency domain feature values, specifically including: Acquire the blue chromaticity of each pixel in the color model of the scrambled image and determine the cosine component of the blue chromaticity; acquire the red chromaticity of each pixel in the color model of the scrambled image and determine the cosine component of the red chromaticity; determine the transformation coefficients based on the blue and red chromaticities; acquire the luminance component of each pixel in the color model of the scrambled image; determine the total number of pixels in the color model of the scrambled image; determine the frequency domain feature values ​​based on the cosine components of the blue and red chromaticities, the transformation coefficients, and the luminance component.

[0024] Specifically, the frequency domain eigenvalues ​​are calculated using the following steps: Step 1: Obtain the coordinates of the current pixel in the color model of the scrambled image, as well as the brightness component, blue chromaticity, and red chromaticity of that pixel.

[0025] Step 2, determine the transformation coefficient: if the horizontal and vertical coordinates of the current pixel are both zero, the transformation coefficient is one divided by the square root of two; otherwise, the transformation coefficient is one.

[0026] Step 3, calculate the cosine component of the blue chromaticity: multiply the blue chromaticity by the cosine of (twice the horizontal axis plus one) multiplied by half the value of pi, and then multiply it by the cosine of (twice the vertical axis plus one) multiplied by half the value of pi.

[0027] Step 4: Calculate the cosine component of the red chromaticity: The method is the same as in Step 3, except that the blue chromaticity is replaced with the red chromaticity.

[0028] Step 5: Calculate the cosine component of the luminance component: The method is the same as in Step 3, except that the blue chromaticity is replaced with the luminance component.

[0029] Step six: Add the cosine component of the blue chromaticity to the cosine component of the red chromaticity, and then multiply by the transformation coefficient to obtain the chromaticity cosine sum.

[0030] Step 7: Multiply the cosine component of the luminance component by the transformation coefficient to obtain the luminance cosine weighted value.

[0031] Step 8: Add the weighted values ​​of the chromaticity cosine and luminance cosine, and then divide by the total number of pixels to obtain the frequency domain feature value.

[0032] This frequency domain feature value is used to describe the frequency domain data of the color model of the scrambled image. The color model of the scrambled image is digitized so that the single scrambled animal image corresponding to the color model of the scrambled image can be compressed and encoded.

[0033] In some embodiments, obtaining the number of bits for each run-length compressed code in the run-length compressed code set, determining the binary length set of each code, and determining the truncation-priority key-value pair sequence based on the binary length set of each code, specifically includes: Obtain the number of binary bits for each run-length compressed code in the run-length compressed code set, and use the set of all bits as the binary length set of each code; determine the starting random code set based on the binary length set of each code; determine the priority number set; and determine the truncation-priority key-value pair sequence based on the priority number set and the starting random code set.

[0034] In practice, each bit in the set of binary lengths of each encoding is used as the maximum value of the random number generator, and a random number is generated in sequence. This random number is used as the starting random code for the corresponding run-length compression code, and the set of all starting random codes is the starting random code set. A set of non-repeating random numbers is generated in sequence as the concatenation priority number for each run-length compression code, and the set of all priority numbers is the priority number set. An empty key-value pair sequence is created, and each priority number in the priority number set is used as the key of the sequence, and the corresponding starting random code in the starting random code set is used as the value of the sequence. The sequence composed of all key-value pairs is the truncation-priority key-value pair sequence.

[0035] In some embodiments, determining the set of coded segments to be concatenated based on the truncation-priority key-value pair sequence and the run-length compression coding set specifically includes: For each run-length compressed code in the run-length compressed code set, determine the start code of the run-length compressed code; determine the code segment length of the run-length compressed code; according to the start code and the code segment length, extract the corresponding sub-code from the run-length compressed code as the code segment to be concatenated; and take the set of all code segments to be concatenated as the code segment set.

[0036] In practice, the value corresponding to each run-length compressed code in the truncation-priority key-value pair sequence is used as its start code. The length of the encoded segment is determined by calculating the proportion of the number of bits of each run-length compressed code to the total number of bits of all run-length compressed codes, and determining a truncation length based on this proportion. Starting from the start code, the substring of the specified number is truncated from the run-length compressed code to obtain the encoded segment to be concatenated.

[0037] In some embodiments, determining the final combined encoding based on the truncation-priority key-value pair sequence and the set of encoding segments to be concatenated specifically includes: The splicing priority number of each coded segment to be spliced ​​in the set of coded segments to be spliced ​​is obtained according to the truncation-priority key-value pair sequence; the coded segments to be spliced ​​are sorted according to the splicing priority number and spliced ​​in order to obtain the final combined code.

[0038] In practice, each key in the priority key-value pair sequence is traversed and used as the concatenation priority number of the corresponding code segment to be concatenated; the code segments to be concatenated are sorted in ascending order of concatenation priority number; and all sorted codes are concatenated end to end in order to form the final combined code.

[0039] Further, the animal traceability private key and animal traceability public key are determined based on the final combined encoding: the private key length and format are determined according to the encryption algorithm used in the data encryption system of this application; the final combined encoding is formatted using a private key information formatting algorithm in the cryptographic standards of the prior art; the final combined encoding is hashed according to the required private key length to convert its length into the specified private key length, thereby obtaining the animal traceability private key; the corresponding animal traceability public key is derived from the private key using an elliptic curve cryptography algorithm.

[0040] In some embodiments, the animal lifecycle traceability data is encrypted and stored according to the animal traceability public key, specifically including: Based on the existing ASCII code table, the animal lifecycle traceability data is converted into a plaintext string using character mapping. This plaintext string is a pure numeric encoding. A random number is generated using a random number generator and used as an encryption random number. Using an elliptic curve cryptography algorithm, this encryption random number is encrypted into a random number ciphertext using the animal traceability public key. Then, using the elliptic curve cryptography algorithm again, each bit of the plaintext traceability data is encrypted using the animal traceability public key to obtain a ciphertext traceability data string. The random number ciphertext and the ciphertext traceability data string are stored together in off-chain storage space and blockchain evidence storage.

[0041] In some embodiments, decrypting and reading the animal's full life cycle traceability data based on the animal traceability private key specifically includes: A blockchain user sends a data read command on the blockchain client. After receiving the command, the blockchain server retrieves the corresponding traceability data encrypted string and random number encrypted string from the off-chain storage space and the blockchain evidence storage, and sends them to the blockchain client. The blockchain client uses an elliptic curve decryption algorithm with the animal traceability private key to decrypt the traceability data encrypted string, removes the random number encrypted part, and obtains the traceability data plaintext string. The data decoder is then used to decode the traceability data plaintext string to restore the animal's full life cycle traceability data.

[0042] The technical solution provided in this application firstly involves performing complexity screening on a single original animal image to determine the selected animal image. This increases the basic complexity of the selected animal image, thereby reducing its predictability and effectively avoiding the problem of an overly simple generated key due to insufficient image complexity, thus improving the unpredictability of the generated key. Secondly, the selected animal image is scrambled and compressed before encoding. Scrambling increases the randomness of run-length compression coding, while compression reduces its repetitiveness, thereby reducing the predictability of run-length compression coding and increasing its complexity. Then, a truncation-priority key-value pair is generated based on random numbers. The sequence is used to determine the final combined code, improving the randomness of the run-length compression coding combination process and reducing the predictability of the final combined code. Furthermore, using the truncation-priority key-value pair sequence to partially truncate and randomly combine the run-length compression code can avoid the problem of key leakage due to the leakage of a single screened animal image, further improving the security of the key. Finally, the animal traceability private key and animal traceability public key generated from the screened animal images are used to decrypt, read, and encrypt the animal's entire life cycle traceability data, reducing the predictability of the private key source and effectively avoiding blockchain data security problems caused by blockchain private key prediction, thus improving the security of blockchain data encryption. Attached Figure Description

[0043] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0044] Figure 1 This is an exemplary flowchart of a blockchain-based animal lifecycle traceability method according to some embodiments of this application; Figure 2 These are schematic diagrams of exemplary hardware and / or software of a key generation unit shown in some embodiments of this application; Figure 3 This is a schematic diagram of the structure of a computer device for implementing a blockchain-based animal life cycle traceability method according to some embodiments of this application. Detailed Implementation

[0045] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0046] This application provides a blockchain-based method, system, device, and storage medium for tracing the entire life cycle of animals. The core of this method involves receiving animal life cycle tracing data and a set of original animal images; performing complexity filtering on each individual original animal image in the set to determine a filtered set of animal images; generating a set of random scrambling matrices; scrambling and compressing each filtered animal image in the set of images according to the random scrambling matrices, followed by encoding to determine a run-length compression encoding set; determining a truncation-priority key-value pair sequence based on the run-length compression encoding set; determining a set of encoding segments to be concatenated based on the truncation-priority key-value pair sequence and the run-length compression encoding set, thereby determining the final combined encoding; determining the animal tracing private key and animal tracing public key based on the final combined encoding; and decrypting, reading, and encrypting the animal life cycle tracing data using the animal tracing private key and animal tracing public key, thereby reducing the predictability of blockchain keys and improving the security of blockchain data encryption.

[0047] To better understand the above technical solutions, a detailed description of the solutions will be provided below in conjunction with the accompanying drawings and specific implementation methods. (Reference) Figure 1 The figure is an exemplary flowchart of a blockchain-based animal lifecycle traceability method according to some embodiments of this application. The blockchain-based animal lifecycle traceability method mainly includes the following steps: Step 101: Receive animal life cycle traceability data and a set of original animal images, perform complexity filtering on each individual original animal image in the set of original animal images, determine the set of filtered animal images and the total number of filtered images in the set of filtered animal images, and generate a set of random scrambling matrices based on the total number of filtered images.

[0048] In practice, after successful user security verification, the user sends the animal's entire lifecycle traceability data and multiple individual original animal images to the blockchain client. The blockchain server receives the animal's entire lifecycle traceability data and each individual original animal image, and uses the collection of all individual original animal images as the animal original image set. In this application, the animal original images are used for image complexity filtering to obtain the images used for key generation, i.e., the filtered animal images.

[0049] In this embodiment, the complexity screening of each individual original animal image in the original animal image set to determine the screened animal image set and the total number of screened images in the screened animal image set can be achieved by the following steps: Determine the acceptable threshold for image complexity; For each individual original animal image in the set of original animal images, the pixel distribution uniformity of the individual original animal image is determined, thereby determining the image content complexity of the individual original animal image; Based on the complexity of the image content, a single original animal image is filtered to determine the single filtered animal image; The collection of all individually filtered animal images is used as the filtered animal image set; Determine the number of all individual filtered animal images, and use this number as the total number of filtered images.

[0050] In specific implementation, different ranges of animal image feature dispersion uniformity are defined corresponding to different image content complexity. The range of animal image feature dispersion uniformity in which the pixel distribution uniformity of a single original animal image falls is determined, and the image content complexity corresponding to this range is used as the image content complexity of a single original animal image. The image content complexity of a single original animal image is used to filter single animal images that meet security standards, ensuring the security of the final animal traceability private key generated from the single filtered animal image. The higher the image content complexity of a single filtered animal image, the lower the predictability of the final animal traceability private key generated from the single filtered animal image, and the higher the security of the final animal traceability private key.

[0051] If the image content complexity of a single original animal image is lower than the image complexity threshold, the image is not considered a selected animal image, and the user needs to resend the single original animal image on the client. If the image content complexity of a single original animal image exceeds the image complexity threshold, the image is considered a selected animal image, and the process continues to evaluate the next single original animal image until all single original animal images in the animal image set have been evaluated. The image complexity threshold in this application is set through statistical analysis of a large amount of data. Other methods can also be used in other embodiments, and this is not limited here.

[0052] In this embodiment, the pixel distribution uniformity of the original image of a single animal can be determined by the following steps: Determine the pixel transformation matrix of the original image; Determine the pixel contrast factor of the pixel transformation matrix of the original image; Obtain the grayscale levels of the starting and ending points during pixel traversal of a single original animal image; Determine the difference between adjacent gray levels of this gray level in the pixel transformation matrix of the original image; The dispersion of a gray level in the pixel transformation matrix of the original image is determined based on the difference between adjacent gray levels and the gray level itself. The pixel distribution uniformity of a single animal original image is determined by using the pixel contrast factor of the original image pixel transformation matrix, the gray level of the starting point and the gray level of the ending point during the pixel traversal of a single animal original image, the difference between adjacent gray levels of the gray level in the original image pixel transformation matrix, and the dispersion of adjacent gray levels of the gray level in the original image pixel transformation matrix.

[0053] The calculation method for the difference between adjacent gray levels is as follows: multiply the gray level by the reciprocal of the pixel contrast factor, and then multiply by an exponential function value with the natural constant as the base and the gray level as the exponent. The calculation method for the dispersion of adjacent gray levels is as follows: multiply the difference between adjacent gray levels by the gray level, and then multiply by an exponential function value with the natural constant as the base and the negative difference between the adjacent gray levels as the exponent.

[0054] It should be noted that, in this application, the pixel distribution uniformity of a single animal original image is used as an indicator to measure the distribution trend of pixel gray values ​​in a single animal original image, thereby judging the image content complexity of a single animal original image. The higher the pixel distribution uniformity of a single animal original image, the more dispersed the distribution trend of pixel gray values ​​in the single animal original image, the more changes in pixel gray values, and the higher the image content complexity of the single animal original image.

[0055] In a specific implementation, the eigenvalues ​​can be determined by using a characteristic polynomial on the original image pixel transformation matrix. These eigenvalues ​​are then used as the pixel contrast factor of the original image pixel transformation matrix. This pixel contrast factor is used to describe the basic scaling factor that describes the grayscale value changes of pixels in a single original animal image.

[0056] Furthermore, the generation of the original image pixel transformation matrix is ​​as described above and will not be repeated here.

[0057] In practical implementation, a random number generator can be used to generate a single random scrambling matrix. The total number of images to be screened is used as the number of single random scrambling matrices generated, resulting in all single random scrambling matrices. The set of all single random scrambling matrices is then considered as the random scrambling matrix set. In this application, the random scrambling matrix is ​​used to scramble the pixel grayscale values ​​and pixel positions of a single screened animal image.

[0058] It should be noted that in this application, the complexity of a single original animal image is screened to determine the selected animal image, thereby increasing the basic complexity of the selected animal image and reducing its predictability. This effectively avoids the problem of the final generated key being too simple due to insufficient image complexity, and improves the unpredictability of the generated key.

[0059] Step 102: Based on the random scrambling matrix set, scramble each individual animal image in the selected animal image set to determine the scrambled animal image set. Compress each individual scrambled animal image in the scrambled animal image set to determine the run-length compression code for each individual scrambled animal image, and then determine the run-length compression code set.

[0060] In this embodiment, the following steps can be used to scramble each individual animal image in the selected animal image set according to the random scrambling matrix set, thereby determining the scrambled animal image set: For each individual random scrambling matrix in the set of random scrambling matrices, the corresponding single filtered animal image is converted into an animal image matrix block according to the single random scrambling matrix; The grayscale matrix blocks of the animal image are determined based on the block division of the animal image matrix; The grayscale matrix block of the animal image is scrambled according to the single random scrambling matrix to determine the scrambled grayscale matrix block; The scrambled grayscale matrix blocks are converted into a single scrambled animal image.

[0061] In specific implementation, the single filtered animal image is divided into animal image matrix blocks with the same number of rows and columns as a single random scrambling matrix. The grayscale value of each element in each animal image matrix block is obtained, and each grayscale value is sequentially read into an empty matrix, which is then used as the animal image grayscale matrix block. Each element value in the animal image grayscale matrix block is either different from or scrambled with each element value in the single random scrambling matrix. The scrambling result is used as the grayscale scrambling result matrix. All grayscale column vectors are extracted from the grayscale scrambling result matrix using a diagonal traversal method. All scrambled matrix column vectors are extracted from the single random scrambling matrix using a diagonal traversal method. Each scrambled matrix column vector is sorted, and the corresponding grayscale column vectors are sorted according to the sorting result. All sorted grayscale column vectors are then recombined to form the scrambled grayscale matrix block. Converting the scrambled grayscale matrix block into a single scrambled animal image can be achieved using image conversion methods from existing image processing libraries. Other methods can also be used in other embodiments, and are not limited here.

[0062] In this embodiment, the run-length compression code for each individual scrambled animal image in the scrambled animal image set is determined, and the run-length compression code set is then determined, which can be achieved through the following steps: For each individual scrambled animal image in the scrambled animal image set, the individual scrambled animal image is converted to the color model of the scrambled image; The color model of the scrambled image is subjected to component conversion processing to determine the frequency domain feature values. The frequency domain feature values ​​are subjected to discrete level mapping to obtain a discrete level mapping matrix, and then the Z-shaped traversal array is determined. The run-length compression code of each scrambled animal image is determined based on the zigzag traversal array, and then the run-length compression code of each scrambled animal image is determined.

[0063] In specific implementation, each scrambled animal image in the scrambled animal image set is divided into matrix blocks. Each matrix block is converted into a brightness and color-separated image model using an image processing library based on existing image model conversion methods, where color separation is achieved by separating blue and red chromaticity. A frequency domain feature value interval is set as the discrete level, and the values ​​of the frequency domain feature values ​​are mapped to the discrete levels to generate a discrete level mapping matrix. The rows of this matrix represent the values ​​of the frequency domain feature values, and the columns represent the corresponding discrete levels. This discrete level mapping matrix can be read using a zigzag traversal method, and all reading results are used as a zigzag traversal array. The consecutively repeated values ​​and their repetition counts in the zigzag traversal array are counted, and the repetition counts and corresponding consecutively repeated values ​​are arranged as run-length compression encoding.

[0064] In this embodiment, the frequency domain feature values ​​can be determined by performing component conversion on the color model of the scrambled image, which can be achieved using the aforementioned frequency domain feature value calculation steps.

[0065] It should be noted that in this application, the animal images after screening are scrambled and compressed before being encoded. Scrambling can improve the randomness of run-length compression coding, and compression can reduce the repetitiveness of run-length compression coding, thereby reducing the predictability of run-length compression coding and increasing the complexity of run-length compression coding.

[0066] Step 103: Obtain the number of bits of each run-length compressed code in the run-length compressed code set, determine the binary length set of each code, and determine the truncation-priority key-value pair sequence based on the binary length set of each code.

[0067] In practice, the number of bits of each run-length compressed code in the run-length compressed code set is obtained, and the set of all bits is used as the binary length set of each code. This binary length set is used to determine the code segment length of each run-length compressed code in the run-length compressed code set.

[0068] In this embodiment, determining the truncation-priority key-value pair sequence based on the set of encoded binary lengths can be achieved using the following steps: The initial random code set is determined based on the set of binary lengths of each encoding; Determine the priority set; The truncation-priority key-value pair sequence is determined based on the priority number set and the starting random code set.

[0069] In specific implementation, each bit in the set of binary lengths of each encoding is set to the maximum value of a random number to generate random numbers sequentially. These random numbers are used as the starting random code for truncation, and the set of all starting random codes is used as the starting random code set. This starting random code set is used to determine the truncation position of each run-length compressed code in the run-length compressed code set. Non-repeating random numbers are generated sequentially as the concatenation priority number for the run-length compressed code arrangement in the run-length compressed code set. The set of all concatenation priority numbers is used as the priority number set, which is used to determine the combination order of the run-length compressed codes in the run-length compressed code set. An empty key-value pair sequence is generated, and each concatenation priority number in the priority number set is used as the key of the sequence, and the corresponding value in the starting random code set is used as the value of the sequence. All combinations of keys and values ​​are used as the truncation-priority key-value pair sequence, which is used to determine the truncation position of each run-length compressed code in the run-length compressed code set.

[0070] It should be noted that in this application, a truncation-priority key-value pair sequence is generated based on random numbers to determine the final combined code, thereby improving the randomness of the run-length compression coding combination process and reducing the predictability of the final combined code.

[0071] Step 104: Determine the set of coded segments to be spliced ​​based on the truncation-priority key-value pair sequence and the run-length compression code set; determine the final combined code based on the truncation-priority key-value pair sequence and the set of coded segments to be spliced; and determine the animal traceability private key and animal traceability public key based on the final combined code.

[0072] In this embodiment, determining the set of coded segments to be concatenated based on the truncation-priority key-value pair sequence and the run-length compression code set can be achieved using the following steps: For each run-length compression code in the run-length compression code set, determine the start code of that run-length compression code; Determine the length of the encoded segment in the run-length compression encoding; The encoding segment to be concatenated is determined based on the start code and the length of the encoding segment; The set of all coded segments to be concatenated is taken as the set of coded segments to be concatenated.

[0073] In specific implementation, the corresponding value of the run-length compressed code in the truncation-priority key-value pair sequence is used as the start code; the code segment length of the run-length compressed code is determined according to the proportion of the number of bits of each run-length compressed code to the total number of bits of all run-length compressed codes in the run-length compressed code set; the start code is used as the truncation start position of the run-length compressed code in the corresponding run-length compressed code set, and the code segment length of the run-length compressed code in the run-length compressed code set is extracted from the truncation start position as the code segment to be spliced.

[0074] In this embodiment, determining the final combined encoding based on the truncation-priority key pair sequence and the set of encoding segments to be concatenated can be achieved through the following steps: The concatenation priority number of each coded segment to be concatenated in the set of coded segments to be concatenated is obtained based on the truncation-priority key-value pair sequence; The final combined code is determined based on the splicing priority number and the coded fragment to be spliced.

[0075] In specific implementation, each key in the truncation-priority key-value pair sequence is obtained in a loop, and each key is used as the splicing priority number of the corresponding segment to be spliced; the splicing priority number is used as the sorting order of the corresponding segments to be spliced, the segments to be spliced ​​in the set of segments to be spliced ​​are sorted, and the set of sorting results is combined in order as the final combined code.

[0076] In specific implementation, the private key length and format can be determined according to the encryption algorithm used in the data encryption system of this application. Different encryption algorithms have different standards for private key length and format. The formatting process is performed using the private key information formatting algorithm in the cryptographic standard of the prior art. The final combined code can be hashed according to the private key length to convert the length of the final combined code into the private key length. The conversion result is used as the animal traceability private key. The animal traceability public key can be generated by the elliptic curve cryptography algorithm in the prior art.

[0077] It should be noted that the animal traceability public key generated from the animal traceability private key in this application can be generated using the existing elliptic curve cryptography algorithm. Other methods can also be used in other embodiments, and this is not limited here. In addition, this application uses truncation-priority key-value pair sequence pairs for partial truncation and random permutation and combination using run-length compression encoding, which can avoid the problem of key leakage due to leakage of animal images after single screening, and further improve the security of the key.

[0078] Step 105: Encrypt and store the animal life cycle traceability data according to the animal traceability public key, and decrypt and read the animal life cycle traceability data according to the animal traceability private key.

[0079] In this embodiment, the encrypted storage of the animal's full life cycle traceability data based on the animal traceability public key can be achieved through the following steps: The animal lifecycle traceability data is converted into a plaintext string by character mapping using the ASCII code table in the existing technology. The plaintext string is a pure numeric encoding. A random number is generated using a random number generator and used as an encryption random number. The encryption random number is then encrypted into a random number ciphertext using the elliptic curve cryptography algorithm based on the animal traceability public key. Each bit of the plaintext string is then encrypted using the elliptic curve cryptography algorithm, and the encryption result is used as the ciphertext string. The random number ciphertext and the ciphertext string are stored in off-chain storage and blockchain notarization.

[0080] In this embodiment, the decryption and reading of the animal's full life cycle traceability data based on the animal traceability private key can be achieved through the following steps: A blockchain user sends a data read command on the blockchain client. The blockchain server receives the command and retrieves the encrypted traceability data string and the encrypted random number from the off-chain storage space and the blockchain notarization. The server then sends the retrieved data to the blockchain client. The blockchain client uses an elliptic curve cryptography algorithm based on the animal traceability private key to remove the encrypted random number portion from the encrypted traceability data string. The result is used as the plaintext traceability data string. The plaintext traceability data string is then decoded using a data decoder to obtain the animal's full lifecycle traceability data.

[0081] It should be noted that this application uses the animal traceability private key and animal traceability public key generated from a single screened animal image to decrypt, read, and encrypt the animal's full life cycle traceability data. This can effectively avoid blockchain data security issues caused by blockchain private key prediction and improve the security of blockchain data encryption.

[0082] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A blockchain-based method for tracing the entire life cycle of animals, characterized in that, Includes the following steps: Receive animal life cycle traceability data and a set of original animal images, perform complexity filtering on each individual original animal image in the set of original animal images, determine the set of filtered animal images and the total number of filtered images in the set of filtered animal images, and generate a set of random scrambling matrices based on the total number of filtered images; The random scrambling matrix set is used to scramble each individual animal image in the selected animal image set to determine the scrambled animal image set. Each individual scrambled animal image in the scrambled animal image set is then compressed to determine the run-length compression code for each individual scrambled animal image, thereby determining the run-length compression code set. Obtain the number of bits for each run-length compressed code in the run-length compressed code set, determine the binary length set of each code, and determine the truncation-priority key-value pair sequence based on the binary length set of each code; The set of coded segments to be spliced ​​is determined based on the truncation-priority key-value pair sequence and the run-length compression code set; the final combined code is determined based on the truncation-priority key-value pair sequence and the set of coded segments to be spliced; and the animal traceability private key and animal traceability public key are determined based on the final combined code. The animal's entire life cycle traceability data is encrypted and stored using the animal traceability public key, and decrypted and read using the animal traceability private key.

2. The method as described in claim 1, characterized in that, The process of filtering each individual original animal image in the original animal image set based on complexity, and determining the filtered animal image set and the total number of filtered images in the filtered animal image set, specifically includes: For each individual original animal image in the set of original animal images, determine the image content complexity of the individual original animal image; A single original animal image whose image content complexity exceeds the acceptable threshold is used as a single filtered animal image, thereby determining the set of filtered animal images. The order of magnitude of the filtered animal image set is taken as the total number of images filtered.

3. The method as described in claim 2, characterized in that, Determining the image content complexity of a single original animal image specifically includes: Determine the pixel transformation matrix of the original image based on a single original animal image; The pixel distribution uniformity of a single animal original image is determined based on the original image pixel transformation matrix; Set the range for the uniformity of animal image feature dispersion; The image content complexity of a single animal original image is determined based on the pixel distribution uniformity and the range of animal image feature dispersion uniformity.

4. The method as described in claim 3, characterized in that, Determining the pixel distribution uniformity of a single animal original image based on the original image pixel transformation matrix specifically includes: Determine the pixel contrast factor of the pixel transformation matrix of the original image; Obtain the grayscale levels of pixels in a single original animal image; Determine the difference between adjacent gray levels in the original image pixel transformation matrix; The dispersion of the gray level in the pixel transformation matrix of the original image is determined based on the difference between the adjacent gray levels and the gray level. The pixel distribution uniformity of a single animal original image is determined based on the pixel contrast factor of the original image pixel transformation matrix, the gray level of the pixels in the single animal original image, the difference between adjacent gray levels, and the dispersion of adjacent gray levels. The pixel distribution uniformity of the single animal original image is calculated in the following manner: First, obtain the total number of rows and columns of the pixel transformation matrix of the original image, and multiply the two to get the total number of elements; Then, for each element in the matrix, the following steps are performed sequentially: obtain the pixel contrast factor corresponding to the element; obtain the gray level of the starting point and the gray level of the ending point during the pixel traversal of a single animal original image, and calculate their sum; obtain the difference between adjacent gray levels of the starting point gray level and the difference between adjacent gray levels of the ending point gray level, and calculate their sum; divide the sum of the gray levels of the starting point and the ending point by the sum of the aforementioned differences to obtain a first ratio; obtain the dispersion of adjacent gray levels of the starting point gray level and the dispersion of adjacent gray levels of the ending point gray level, calculate their sum, and then divide by two to obtain a second ratio; multiply the pixel contrast factor, the first ratio, and the second ratio to obtain a temporary result for the element. Next, sum up the temporary results of all elements; Finally, divide the sum by the total number of elements, and the quotient is the pixel distribution uniformity of the original image of the single animal.

5. The method as described in claim 1, characterized in that, Based on the random scrambling matrix set, each individual animal image in the selected animal image set is scrambled, and the scrambled animal image set is determined specifically as follows: For each individual random scrambling matrix in the set of random scrambling matrices, the single filtered animal image corresponding to that individual random scrambling matrix is ​​converted into an animal image matrix block; The grayscale matrix blocks of the animal image are determined based on the block division of the animal image matrix; The grayscale matrix block of the animal image is scrambled according to the single random scrambling matrix to determine the scrambled grayscale matrix block; The scrambled grayscale matrix block is converted into a single scrambled animal image, thereby determining the set of scrambled animal images.

6. The method as described in claim 1, characterized in that, Compressing each individual scrambled animal image in the scrambled animal image set involves determining the run-length compression code for each individual scrambled animal image, specifically including: For each individual scrambled animal image in the scrambled animal image set, convert the individual scrambled animal image to the color model of the scrambled image; The color model of the scrambled image is subjected to component transformation to determine the frequency domain feature values. The frequency domain eigenvalues ​​are subjected to discrete level mapping to obtain a discrete level mapping matrix, which is then used to determine the Z-shaped traversal array. The run-length compression code of each scrambled animal image is determined based on the zigzag traversal array, and then the run-length compression code of each scrambled animal image is determined.

7. The method as described in claim 1, characterized in that, Determining the set of coded segments to be concatenated based on the truncation-priority key-value pair sequence and the run-length compression coding set specifically includes: For each run-length compression code in the run-length compression code set, determine the start code and code segment length of the run-length compression code; The run-length compression code start code and code segment length are used to determine the code segment to be spliced ​​corresponding to the run-length compression code, and then the set of code segments to be spliced ​​is determined.

8. A blockchain-based animal lifecycle traceability system, characterized in that, It includes a key generation unit, the key generation unit comprising: The scrambling matrix generation module is used to receive animal life cycle traceability data and a set of original animal images, perform complexity filtering on each single original animal image in the set of original animal images, determine the set of filtered animal images and the total number of filtered images in the set of filtered animal images, and generate a set of random scrambling matrices based on the total number of filtered images. The scrambling and compression module is used to scramble each individual animal image in the selected animal image set according to the random scrambling matrix set, thereby determining the scrambled animal image set, compressing each individual scrambled animal image in the scrambled animal image set to determine the run-length compression code of each individual scrambled animal image, thereby determining the run-length compression code set. The combined sequence generation module is used to obtain the number of bits of each run-length compressed code in the run-length compressed code set, determine the binary length set of each code, and determine the truncation-priority key-value pair sequence based on the binary length set of each code; The public-private key derivation module is used to determine the set of coded segments to be spliced ​​based on the truncation-priority key-value pair sequence and the run-length compression code set, to determine the final combined code based on the truncation-priority key-value pair sequence and the set of coded segments to be spliced, and to determine the animal traceability private key and the animal traceability public key based on the final combined code. The encryption / decryption module is used to encrypt and store the animal's full life cycle traceability data according to the animal traceability public key, and to decrypt and read the animal's full life cycle traceability data according to the animal traceability private key.

9. A computer device, characterized in that, The computer device includes a memory and a processor. The memory is used to store computer programs, and the processor is used to call and run the computer programs from the memory, so that the computer device performs the blockchain-based animal life cycle traceability method according to any one of claims 1 to 7.

10. A computer-readable storage medium storing instructions or code that, when executed on a computer, cause the computer to implement the blockchain-based animal lifecycle traceability method as described in any one of claims 1 to 7.