Opening Speech
"Putting two bachelors together is a pair of chopsticks! At this moment, no matter what kind of mood you are, I wish you a happy holiday!
The book is followed by text. The encryption discussed in this article should be one of the simplest encryption methods! The specific encryption process is described as follows: for example, to encrypt a text file, I will read each character in the text at a time and then encrypt it with the specified key, write it into another text file until all the content in the source text is encrypted and the encrypted ciphertext is written into the target text. So the encryption of a text is over. It's easy! The general idea is so simple, but I have to make some supplements.
Now, you need to add a description of the key selection. For example, if the binary code of character a is 8 bits, how should we choose the key? In this article, the number of digits of the key is random. If the selected key is smaller than 8 bits, you can complete the statement. If the selected key is exactly 8 bits, this is exactly what we want to see most, and no processing is required. If the key is greater than 8 bits, for example, if it is 13 BITs, the 13 BITs form a ring. In this way, you can first take the first 1-8 digits, then take 9-13 digits and 1-3 digits, so that you can keep repeating. This is the key selection.
Let's take a look at the code! In this Code, the key is 13 characters.
#include <stdio.h>#define SIZE 13char encrypt(char ch, char key[],int len){static int i = 0;int j;char key1 = 0;for(j = 0; j < 8; j++){key1 >>= 1;i = (i + j) % len;if(key[i+j] == 1){key1 |= 0x80; }}return ch ^ key1;}int main(){char key[SIZE] = {0,1,1,0,0,1,0,0,0,1,1,1,0};int ch;FILE *pf = fopen("SuperFC","r+");while((ch = fgetc(pf)) != EOF){ch = encrypt(ch,key,13);fseek(pf,-1,SEEK_CUR);fputc(ch,pf);fflush(pf);}fclose(pf);return 0;}
Test text:
Verification:
You can first encrypt the source text, get the encrypted content, and then encrypt the source text again (or the decryption process), and get the content in the test text.