Disclosure of Invention
In view of the above, the present application provides methods and apparatuses for data writing and data reading.
Specifically, the method is realized through the following technical scheme:
according to a first aspect of the present application, a data writing method is proposed, the method comprising:
responding to a data writing request, obtaining target data needing to be written into a storage device, wherein the target data comprises a plurality of data bits, and the storage device is arranged in a printer ink box;
according to a predefined corresponding relation between data bits and bits in the storage device, dispersedly writing each data bit of the target data into a corresponding bit of the storage device; wherein the relative position relationship between the data bits written into the storage device is different from the relative position relationship between the data bits in the original target data.
According to a second aspect of the present application, a data reading method is proposed, the method comprising:
determining target data to be read from a storage device of an ink box of a printer, wherein a plurality of data bits contained in the target data are dispersedly written into corresponding bits of the storage device according to a predefined corresponding relation between the data bits and the bits in the storage device, and the relative position relation between the data bits written into the storage device is different from the relative position relation between the data bits in original target data;
determining the corresponding bit of the data bit contained in the target data in the storage device according to the predefined corresponding relation;
and extracting the written data bits in the determined bits, and combining and restoring the data bits into the target data.
According to a third aspect of the present application, there is provided a data writing apparatus comprising:
the data writing device comprises an acquisition unit, a storage unit and a control unit, wherein the acquisition unit is used for responding to a data writing request and acquiring target data needing to be written into a storage device, and the target data comprises a plurality of data bits, wherein the storage device is arranged in an ink box of the printer;
a writing unit, configured to dispersedly write each data bit of the target data into a corresponding bit of the storage device according to a predefined correspondence between the data bit and a bit in the storage device; wherein the relative position relationship between the data bits written into the storage device is different from the relative position relationship between the data bits in the original target data.
According to a fourth aspect of the present application, there is provided a data reading apparatus comprising:
the first determining unit is used for determining target data needing to be read from a storage device of a printer ink box, a plurality of data bits contained in the target data are dispersedly written into corresponding bits of the storage device according to a predefined corresponding relation between the data bits and the bits in the storage device, and the relative position relation between the data bits written into the storage device is different from the relative position relation between the data bits in original target data;
a second determining unit, configured to determine, according to the predefined correspondence, a bit position in the storage device corresponding to a data bit included in the target data;
and the extraction unit is used for extracting the data bits written in the determined bits and combining and restoring the data bits into the target data.
According to a fifth aspect of the present application, there is provided an electronic device comprising:
a processor;
a memory for storing processor-executable instructions;
wherein the processor implements the method as described in the embodiments of the first and second aspects by executing the executable instructions.
According to a sixth aspect of embodiments of the present application, there is provided a computer-readable storage medium having stored thereon computer instructions which, when executed by a processor, implement the steps of the method as described in the embodiments of the first and second aspects above.
According to the technical scheme provided by the application, the data bits contained in the target data are dispersedly written into the corresponding bits of the storage device of the ink box of the printer, so that the relative position relationship among the data bits written into the storage device is different from the relative position relationship among the data bits in the original target data. By the writing method, the target data written into the storage equipment of the printer ink box is complex in change rule of each field and difficult to summarize, and a manufacturer forging the ink box is difficult to deduce the corresponding relation between the data type and the bit position in the printer ink box according to the change rule of each field, so that the safety of the storage information of the printer ink box is improved.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in this application and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.
It is to be understood that although the terms first, second, third, etc. may be used herein to describe various information, such information should not be limited to these terms. These terms are only used to distinguish one type of information from another. For example, first information may also be referred to as second information, and similarly, second information may also be referred to as first information, without departing from the scope of the present application. The word "if" as used herein may be interpreted as "at … …" or "when … …" or "in response to a determination", depending on the context.
Next, examples of the present application will be described in detail.
A storage device in the printer cartridge is used to record some relevant information of the printer cartridge. The related information may occupy several bytes, each byte is composed of 8 bits, and each bit has one data bit recorded therein. Assuming that the data to be written to the memory device in the printer cartridge is one byte in length and contains 8 data bits, the data takes 8 bits. In the related art, as shown in fig. 1, when it is assumed that target data to be written into a storage device is "10101010" and the data is written into the storage device of a printer cartridge, the 8 data bits are written to a predetermined position in the order of the data bits in the original data (assuming that N bits exist in total in the storage device and the target data is written as first to eighth bits), and the bits occupied by the 8 data bits in the storage device are consecutive to each other.
The relative position relationship between the data written in the storage device by the writing method and each data bit in the original data is completely the same. For example, when the type of the related information to be written is the ink volume of the ink cartridge of the printer, the device performing the writing operation writes the related data every time the ink volume usage reaches a certain value, and a manufacturer of a counterfeit ink cartridge can easily deduce which bits in the storage device are used for recording the ink volume usage from the change of the data bits in the storage device. In the same way, manufacturers of counterfeit ink cartridges can estimate each bit and the written data type in the storage device of the printer ink cartridge, and then counterfeit ink cartridges are counterfeited, which is not beneficial to the safety of data stored in the printer ink cartridge.
The present application provides a data writing method for solving the above problems in the related art.
Fig. 2 is a flow chart illustrating a data writing method according to an exemplary embodiment of the present application. As shown in fig. 2, the following steps may be included:
step 202, in response to a data write request, obtaining target data to be written into a storage device, where the target data includes a plurality of data bits, and the storage device is disposed in a printer cartridge.
In one embodiment, the storage device is disposed in the ink cartridge of the printer, and in order to prevent the data written into the storage device from being modified at will, the storage device may be a read-only memory, or a fixed memory, and the data written into the storage device is fixed after being written into the storage device, and cannot be modified any more, and even if the power supply is cut off, the data will not be lost. Specific types of rom may include programmable rom, erasable programmable rom, electrically erasable programmable rom, etc. The specific type of memory is not limited by this application.
In one embodiment, the target data to be written into the storage device of the printer cartridge may include preset configuration information and/or usage status information of the printer cartridge. The information is generated during the use of the printer cartridge, reflects the use state of the printer cartridge, changes along with the use condition of the printer cartridge, and can be written by the printer provided with the printer cartridge. The configuration information reflecting the printer cartridge is often determined before the printer cartridge is shipped. For example, the serial number information of the printer cartridge can be used to uniquely identify the printer cartridge, and the version information of the printer cartridge can be used to distinguish the printer cartridge from the version of the printer cartridge, and the configuration information does not change with the use of the printer cartridge, and such information can be written into the storage device of the printer cartridge in advance by the debugging device of the printer cartridge.
As can be seen from the above embodiments, the target data may include preset configuration information and/or usage status information of the printer cartridge, and the device performing data writing may be a printer to which the printer cartridge is installed or a debugging device performed by the printer cartridge. It should be noted that, for convenience of understanding, the foregoing embodiments are merely examples of the type of the target data and the type of the writing device, and the application does not limit the type of the target data specifically included and the type of the device performing the data writing operation.
Step 204, according to the predefined corresponding relation between the data bits and the bits in the storage device, dispersedly writing each data bit of the target data into the corresponding bit of the storage device; wherein the relative position relationship between the data bits written into the storage device is different from the relative position relationship between the data bits in the original target data.
In this step, the device performing the write operation needs to dispersedly write each data bit included in the target data into a corresponding bit in the storage device according to the predefined corresponding relationship. Unlike the write method in the related art, the target data written into the storage device has a relative positional relationship between the data bits that is changed compared to the original target data.
This change in relative positional relationship can be embodied in two aspects: firstly, target data is written into the storage device, wherein the sequence of each data bit is different from the sequence of each data bit in the original target data. For example, as shown in fig. 3, assuming that original target data is "110011", data bits of the target data written into the storage device have changed, assuming that predefined correspondence indicates that the writing device writes the target data into the first 6 bits of the storage space, writes a data bit "0" in the third bit into the first bit, writes a data bit "1" in the first bit into the third bit, and swaps the data bits in the fourth and fifth bits, the target data written into the storage device becomes "010101", where the sequence between the data bits is different from the original target data. Of course, the above example is only a very simple example for easy understanding, and the above corresponding relationship in practical application is more complicated.
On the other hand, the relative position relationship of each data bit in the target data can also be changed by changing the adjacent condition between the bits of each data bit in the target data. As shown in fig. 4, still taking the target data as "110011" as an example, assuming that there are 16 bits in the storage device, according to the predefined corresponding relationship, the first data bit "1" is written into the first bit of the 16 bits in the storage device, the second data bit "1" is written into the third data bit, the third data bit "0" is written into the sixth data bit, and the remaining three data bits "011" are written into the eighth to tenth bits, respectively, then the bits where the first four data bits are located are all not adjacent in the storage device, that is, the target data are spaced by other bits (the second, fourth, fifth, and seventh bits), so as to change the relative position relationship of the data bits in the target data. Similarly, the above example is only a very simple example for easy understanding, and it is only necessary to ensure that at least two adjacent data bits in the target data are written into non-adjacent bits in the storage device, and there may be one or more bits in the bit inter-interval where each data bit is located, and the number of bits in different adjacent data bit inter-intervals may be different. Obviously, the bit interval between adjacent data bits can increase the difficulty of an illegal person to guess the data type of the data bit recorded by each bit from the change situation of the data bit recorded in the storage device, and the safety of the data recorded in the storage device is improved.
It should be noted that, in order to further improve the data security, the preset corresponding relationship may simultaneously represent the change of the relative position relationship between the two aspects, that is, the target data written into the storage device may be changed in the relative order between the data bits, in each data bit in the disordered order, or at least two adjacent data bits may be distributed in non-adjacent bits in the storage device. For example, as shown in fig. 5, assuming that there are 16 bits in the storage space and the target data is still "110011", according to the predefined corresponding relationship, the sequence of the data bits in the target data is scrambled to "010101", and also according to the predefined corresponding relationship, the bits occupied by the data bits in the "010101" in the storage space may not be consecutive, for example, a first data bit "0" may be in a first bit in the storage space, a second data bit "1" may be in a third bit in the storage space, a third data bit "0" may be in a sixth bit in the storage space, and the remaining three data bits "011" are in eighth to tenth bits, respectively. In fact, it is sufficient that at least two adjacent data bits exist in "010101" with other bits spaced therebetween.
It is noted that data bits included in other types of data may be written for alternate ones of the bits occupied by the respective data bits in the target data.
In an embodiment, the predefined correspondence may be generated by a printer in which the printer cartridge is located or a debugging device of the printer cartridge, and the predefined correspondence may be stored in the printer cartridge in advance, and may be encrypted for security of the correspondence. The device needing data writing can directly obtain or obtain the corresponding relation prestored in the printer ink box through decryption operation, and write in the data according to the corresponding relation when writing in the data. The predefined correspondence may include correspondence of all types of target data that needs to be written, or correspondence of only a part of types of target data that needs to be written.
In one case, the predefined correspondence may be determined by a manufacturer of the printer cartridge when the storage device has not been written with data, and the predefined correspondence is pre-stored in the printer cartridge, and all devices that need to perform data writing operation write data according to the pre-stored correspondence. In this case, the printer cartridges of different batches and different versions may correspond to different predefined correspondences, and the device that writes data may select an adapted correspondence from the correspondences maintained by the device according to the batch information and version information of the printer cartridges.
In another case, the device performing the data writing operation may randomly select the written bit of the target data from the free bits in the storage device, and then generate the corresponding relationship according to the selected bit and store the corresponding relationship into the printer cartridge, and the device needing to read the data may restore and combine the original form of the data according to the corresponding relationship stored in the printer cartridge. In this case, the correspondence relationship adopted by different printer cartridges when data is written differs.
As can be seen from the above embodiments, after the above processing, the target data written into the storage device has a different sequence from each data bit in the original target data, or the bits occupied by the data bits in the target data written into the storage device are not continuous, or the bits occupied by the data bits in the target data written into the storage device are discontinuous while the sequence of each data bit in the target data written into the storage device is different. By the method for writing data, the sequence of each data bit in the target data can be changed, and the adjacent situation of the bit occupied by each data bit can be changed, so that the distribution of the target data written into the storage device is more complex. Firstly, illegal persons cannot easily summarize the change rule of the data by traversing the data recorded in the storage equipment in different use states of the printer ink box, and further cannot easily infer the data type recorded by each bit in the printer ink box; secondly, because the data recorded in the storage device of the ink box of the printer is disordered and/or the adjacent condition of the bit occupied by each data bit is changed, illegal personnel can not directly know the relevant information of the ink box of the printer from the data recorded in the storage device; the application improves the safety of data recorded by the storage device in the ink box of the printer from the two angles.
Accordingly, fig. 6 is a flowchart illustrating a data reading method according to an exemplary embodiment of the present application. As shown in fig. 6, the following steps may be included:
step 602, determining target data to be read from a storage device of a printer cartridge, wherein a plurality of data bits contained in the target data are dispersedly written into corresponding bits of the storage device according to a predefined corresponding relationship between the data bits and the bits in the storage device, and a relative position relationship between the data bits written into the storage device is different from a relative position relationship between the data bits in original target data.
The data stored in the storage device in the printer cartridge can embody the relevant information of the printer cartridge, such as the preset configuration information and the use state information of the printer cartridge. In some cases, the relevant device needs to read data in the storage device, for example, a printer with a mounted printer cartridge may determine relevant usage of the printer cartridge by reading data in the storage device, specifically, version information of the printer cartridge may be recorded in the storage device, the printer may determine whether the printer cartridge of the version is usable by reading the version information, and if the printer cartridge is unusable, the printer may alarm to remind a user to replace the printer cartridge. Alternatively, the printer manufacturer may read the serial number of the printer cartridge to determine whether the printer cartridge is a normal cartridge produced by the printer manufacturer. The present application does not limit the type of device that performs the read operation.
However, since the relative positional relationship between the data bits in the target data written into the storage device by the above-mentioned data writing method is already different from the original target data, the device performing the reading operation needs to restore the original target data according to the predefined corresponding relationship.
Step 604, determining the corresponding bit of the data bit contained in the target data in the storage device according to the predefined corresponding relation.
And 606, extracting the data bits written in the determined bits, and combining and restoring the data bits into the target data.
In the above step, the device performing the read operation may determine, according to the predefined correspondence relation related to the target data, the bit where each data bit included in the target data is located in the storage device. And then extracts the recorded data bits among the bits. In consideration of the fact that the sequence of each data bit contained in the target data written into the storage device may also be changed, the device performing the reading operation may further determine the original sequence of each bit in the target data according to the predefined correspondence, and combine the extracted data bits according to the original sequence to finally obtain the original target data.
In one case, the predefined correspondence may be obtained from the printer cartridge by the device performing the reading operation. In this case, the correspondence is often already encrypted. The decryption key can be pre-distributed to the equipment with data reading qualification by a manufacturer for producing the printer ink box, and then the equipment can decrypt the corresponding relation in the form of the ciphertext by using the decryption key so as to obtain the corresponding relation in the form of the plaintext. In another case, assuming that the device capable of performing the data reading operation is only the device capable of performing the data writing operation, the correspondence may be stored only at the device capable of performing the data writing operation, and the correspondence is not maintained in the printer cartridge.
Corresponding to the method embodiments, the present specification also provides an embodiment of an apparatus.
Fig. 7 is a schematic structural diagram of a data writing electronic device or a data reading electronic device according to an exemplary embodiment of the present application. Referring to fig. 7, at the hardware level, the electronic device includes a processor 702, an internal bus 704, a network interface 706, a memory 708, and a non-volatile storage 710, although it may also include hardware required for other services. The processor 702 reads a corresponding computer program from the non-volatile memory 710 into the memory 708 and then runs, forming a data writing means or a data reading means on a logical level. Of course, besides the software implementation, the present application does not exclude other implementations, such as logic devices or a combination of software and hardware, and the like, that is, the execution subject of the following processing flow is not limited to each logic unit, and may also be hardware or logic devices.
Fig. 8 is a block diagram illustrating a data writing apparatus according to an exemplary embodiment of the present application. Referring to fig. 8, the apparatus includes an obtaining unit 802, a writing unit 804, wherein:
an obtaining unit 802, configured to obtain target data to be written into a storage device in response to a data writing request, where the target data includes a plurality of data bits, and the storage device is disposed in an ink cartridge of a printer;
a writing unit 804, configured to dispersedly write each data bit of the target data into a corresponding bit of the storage device according to a predefined correspondence between the data bit and a bit in the storage device; wherein the relative position relationship between the data bits written into the storage device is different from the relative position relationship between the data bits in the original target data.
Optionally, the relative position relationship includes: the sequence between each data bit.
Optionally, the relative position relationship includes: the adjacency between individual data bits; wherein at least two adjacent data bits in the target data are written to non-adjacent bits in the storage device.
Optionally, the target data includes: the preset configuration information and/or the use state information of the printer ink box.
Optionally, the data write request comes from a printer where the printer cartridge is located, or comes from a commissioning device connected to the printer cartridge.
In correspondence with the above method embodiments, the present specification also provides another apparatus embodiment.
Fig. 9 is a block diagram illustrating a traffic scheduling apparatus according to an exemplary embodiment of the present application. Referring to fig. 9, the apparatus includes a first determining unit 902, a second determining unit 904, and an extracting unit 906, wherein:
a first determining unit 902, configured to determine target data to be read from a storage device of a printer cartridge, where a plurality of data bits included in the target data are dispersedly written into corresponding bits of the storage device according to a predefined correspondence between data bits and bits in the storage device, and a relative positional relationship between data bits written into the storage device is different from a relative positional relationship between data bits in original target data;
a second determining unit 904, configured to determine, according to the predefined correspondence, a bit position in the storage device corresponding to a data bit included in the target data;
and an extracting unit 906, configured to extract the data bits written in the determined bits, and combine and restore the data bits into the target data.
The implementation process of the functions and actions of each unit in the above device is specifically described in the implementation process of the corresponding step in the above method, and is not described herein again.
For the device embodiments, since they substantially correspond to the method embodiments, reference may be made to the partial description of the method embodiments for relevant points. The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of the application. One of ordinary skill in the art can understand and implement it without inventive effort.
In an exemplary embodiment, there is also provided a non-transitory computer readable storage medium, for example a memory, comprising instructions executable by a processor of a data writing apparatus to implement a method as in the above embodiments, such as the method may comprise:
responding to a data writing request, obtaining target data needing to be written into a storage device, wherein the target data comprises a plurality of data bits, and the storage device is arranged in a printer ink box; according to a predefined corresponding relation between data bits and bits in the storage device, dispersedly writing each data bit of the target data into a corresponding bit of the storage device; wherein the relative position relationship between the data bits written into the storage device is different from the relative position relationship between the data bits in the original target data.
Accordingly, in an exemplary embodiment, there is also provided a non-transitory computer readable storage medium comprising instructions, e.g. a memory comprising instructions, executable by a processor of a data reading apparatus to implement a method as in the above embodiments, such as the method may comprise:
determining target data to be read from a storage device of an ink box of a printer, wherein a plurality of data bits contained in the target data are dispersedly written into corresponding bits of the storage device according to a predefined corresponding relation between the data bits and the bits in the storage device, and the relative position relation between the data bits written into the storage device is different from the relative position relation between the data bits in original target data; determining the corresponding bit of the data bit contained in the target data in the storage device according to the predefined corresponding relation; and extracting the written data bits in the determined bits, and combining and restoring the data bits into the target data.
The non-transitory computer readable storage medium may be a ROM, a Random Access Memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc., which is not limited in this application.
The above description is only exemplary of the present application and should not be taken as limiting the present application, as any modification, equivalent replacement, or improvement made within the spirit and principle of the present application should be included in the scope of protection of the present application.