E-file character ISN transposition encryption method
Technical field: the present invention relates to a kind of computer software technology, particularly e-file character ISN transposition encryption method.
Background technology: in background technology, flourish along with computer technology, types of applications software is also increasing, and these application software generally all can produce corresponding e-file, as word document, cad drawing, jpg picture etc.If comprise security information in these files, but these e-files are not carried out encryption, the content in these e-files is easy to be seen by the people or steal so.Be solving the security management problem of e-file, mainly is to adopt complicated software cryptography algorithm to e-file, and every plaintext of e-file is transformed into corresponding ciphertext.Even encrypt file is stolen, generally can't reads correct information, thereby reach the purpose of protection sensitive data.Usually cryptographic algorithm and decipherment algorithm are present in the application program, cause its security to be subjected to a certain degree restriction, more easily are cracked, and encryption software commonly used such as office office software, encipherors such as winzip, winrar are cracked this point just can be described.For overcoming these defectives, e-file character ISN transposition encryption method is studied.
Summary of the invention: technical matters to be solved by this invention provides a kind of e-file character ISN transposition encryption decryption method, and it can improve the security of e-file effectively, makes it be not easy to crack.
The technical solution adopted for the present invention to solve the technical problems is that it comprises:
(1), arbitrary encrypted characters string that comprises letter, numeral, control character, Chinese and combination thereof is set, the each order of encrypted characters string is got a character, after carrying out ORD computing (obtaining the character ISN) to every, carry out additive operation with fixed value 1, carry out multiplying with fixed value 10, and carry out subtraction with fixed value 9, the result who at every turn obtains circulates and adds up, obtain WORD (16 unsigned ints) type integer S at last, S is composed to variable KEY;
(2), create internal memory stream M1, M2, the file F that will encrypt read source internal memory stream M1, and the pointer of M1 is moved on to the first place; Then, following process is carried out in circulation: the current character of M1 is carried out getting the character ISN after the ORD computing, and this moment, pointer moved on to next character position automatically, and the character ISN is composed to variable C;
(3), after KEY and fixed value 8 are carried out SHR computing (binary bit value moves to right), carry out XOR computing (the logical difference exclusive disjunction of step-by-step) with C, carry out NOT computing (carrying out the reverse computing of binary value by turn) again, then the result is composed to C, again C is write the end of M2;
(4), KEY carries out additive operation with C again, and with the result again fixed value C1 carry out multiplying, carry out additive operation with fixed value C2 again, the result composes to KEY again;
(5), when reading the end of M1 in (2) step, withdraw from circulation, and the content of M2 exports as file F, so far, file F has become ciphertext, ciphering process is finished;
(6), when when deciphering, the encrypted characters string that the reading encrypted process is provided with obtains WORD type integer S according to the same quadrat method of (1) step, and S is composed to KEY;
(7), create internal memory stream M1, M2, the file F that will decipher read source internal memory stream M1, and the pointer of M1 is moved on to the first place; Then, following process is carried out in circulation: read the current character ISN of M1, this moment, pointer moved on to next character position automatically, and the character ISN is composed to variable C and D;
(8), after KEY and fixed value 8 carry out the SHR computing, carry out the XOR computing, carry out the NOT computing again, then the result is composed to C, this moment, C was transformed to expressly, C was write the end of M2 again with C;
(9), KEY carries out additive operation with D again, and with the result again fixed value C1 carry out multiplying, carry out additive operation with fixed value C2 again, the result composes to KEY again;
(10), when reading the end of M1 in (6) step, withdraw from circulation, and the content of M2 exports as file F, so far, file F has become expressly, decrypting process is finished.
The present invention compares the beneficial effect that is produced with background technology:
1, because the present invention is by computing machine e-file store character machine inner code is carried out the mathematical algorithm conversion, improved the complicacy of cryptographic algorithm, variable KEY when having changed each the encryption, and owing to do not contain Crypted password in the encrypt file, so the security that can improve e-file effectively makes it be not easy to crack.
Description of drawings:
Fig. 1 is an encryption flow block diagram of the present invention.
Fig. 2 is a deciphering FB(flow block) of the present invention.
Embodiment: suppose to have text F, its file content is " among the g ", Crypted password be "! #FA ", constant C1, the value of C2 is respectively 52845,22719.
With reference to accompanying drawing 1, ciphering process is as follows:
At first obtain "! " machine inner code be 33, suppose by following computing: (33+1) obtain result 331 behind the * 10-9, again " # ", " F ", " A " done same computing, obtain 341,651,701 respectively, after it is added up 2024, so far, the initial value of KEY is 2024.
Create internal memory stream M1, M2 behind file F importing M1, moves on to the first place with pointer.Following process is carried out in circulation:
Read the current character " g " of M1, obtaining machine inner code is 103, composes 103 and gives variable C.KEY and 8 carries out the SHR computing, and the result gets 7.C and 7 carry out after the XOR computing 96,96 carry out after the NOT computing 159, compose 159 and to give variable C; KEY and C carry out getting 2183 after the additive operation, 2183 with C1 carry out after the multiplying 115360635,115360635 with C2 carry out after the additive operation 115383354,115383354 binary code is got 16 (high-order amputation is not), getting binary sequence is " 1001110000111010 " (being decimal number 39994), and composes to KEY 39994.At this moment, the C variable is 159, and the KEY variable is 39994.C is write M2.
When circulation proceeds to for the second time, read be Chinese character " in " because the ISN of Chinese character is two character lengths, therefore, only read " in " first half of word, promptly obtain machine inner code and be " 214 ", " 214 " are composed to C, through same above computing, getting C at last is 181, and KEY is 31874, when being recycled to for the third time, " in " the latter half machine inner code of word is " 208 ", C be 83, KEY is 58736.
At last, M2 is exported to file F, promptly obtain the machine inner code formed by " 159 ", " 181 ", " 83 " sequence, correspond to character and just become " Gou S ", so far, finished ciphering process.
With reference to accompanying drawing 2, decrypting process is as follows:
To Crypted password "! #FA ", with last identical, at first obtain "! " machine inner code be 33, by following computing: (33+1) obtain result 331 behind the * 10-9, again " # ", " F ", " A " done same computing, obtain 341,651,701 respectively, after it is added up 2024, so far, the initial value of KEY is 2024.
Create internal memory stream M1, M2 will contain the file F importing M1 of ciphertext content for " Gou S ", and pointer is moved on to the first place.
Following process is carried out in circulation:
Read the first half of the current character " Gou " of M1, obtaining machine inner code is 159, composes 159 and gives variable C and D.KEY and 8 carries out the SHR computing, and the result gets 7.C and 7 carry out after the XOR computing 152,152 carry out after the NOT computing 103, compose 103 and to give variable C; KEY and D carry out getting 2183 after the additive operation, 2183 with C1 carry out after the multiplying 115360635,115360635 with C2 carry out after the additive operation 115383354,115383354 binary code is got 16 (high-order amputation is not), getting binary sequence is " 1001110000111010 " (being decimal number 39994), and composes to KEY 39994.At this moment, the C variable is 103, and the KEY variable is 39994.C is write M2.
When circulation proceeds to for the second time, what read is the latter half of " Gou ", promptly obtain machine inner code and be " 181 ", " 181 " are composed to C, through same above computing, getting C at last is 214, KEY is 31874, and when being recycled to for the third time, the machine inner code of " S " is " 83 ", getting C after computing is 208, and KEY is 58736.
At last, M2 is exported to file F, promptly obtain the machine inner code formed by " 103 ", " 214 ", " 208 " sequence, correspond to character and just become " among the g ".So far, finished decrypting process.