- ..clause 1..: What is the encryption?
- ..clause 2..: Caesar code
- ..clause 3..: Exclusive-OR code
- ..clause 4..: Long password
- ..clause 5..: Application of quasi-random number
The encryption is a technology that transforms former data, and prevents the meaning being understood.
However, being possible to return it in not understanding the meaning because it is meaningless is assumption.
It is called a decryption to return it to former data, and calls former data a plaintext.
The encryption is intended because data is not naturally stolen by the third party.
Therefore, code strength is valued unlike other algorithms as for above all.
As for the algorithm deciphered easily no matter how it is high-speed, the usage is limited.
It is said that it is famous Caesar (cesarean) that used the code for the first time in the world.
For instance, if CAESAR (Caesar) is moved by one character, it becomes DBFTBS.
If this is moved to the direction oppositely by one character, former CAESAR can be derived.
The following program applies this to a general binary file.
[ Directions ]
CodeCaesar (input file name, output file name, and password);
- The password is made a numerical value within the range of 0-255.
- If the password is made the number of minuses, it is possible to decode.
If differences with former data are compared, this code is easily deciphered.void CodeCaesar(char finame[],char foname[],int key) { FILE *fi,*fo; int value; fi = fopen(finame,"rb"); if (fi == NULL) return; fo = fopen(foname,"wb"); if (fo == NULL) return; while ((value = getc(fi)) != EOF) { putc(value + key,fo); } fclose(fi); fclose(fo); }
The Caesar code is easily deciphered because it is simple.
Then, use the exclusive-OR to make it to cramped a little more.
It is suitable for the encryption because it becomes a random on the face of things numerical value in the exclusive-OR.
[ Exclusive-OR ]
When the same number is input by calculating the binary number, the output becomes 0.
The following program applies this to a general binary file.
[ Directions ]
CodeExor (input file name, output file name, and password);
- The password is made a numerical value within the range of 0-255.
- It is possible to decode by the same password.
Though this code is never deciphered only by glancingvoid CodeExor(char finame[],char foname[],int key) { FILE *fi,*fo; int value; fi = fopen(finame,"rb"); if (fi == NULL) return; fo = fopen(foname,"wb"); if (fo == NULL) return; while ((value = getc(fi)) != EOF) { putc(value ^ key,fo); } fclose(fi); fclose(fo); }
The decipherment is easy because there are only 256 kinds of passwords in a current encryption.
Then, a longer password should be able to be used.
The idea is simple. Only have to use two or more numerical values repeatedly.
The following program applies this to a general binary file.
[ Directions ]
CodeExor (input file name, output file name, and password character string);
- The password can specify the character string of arbitrary length.
- It is possible to decode by the same password.
As a result, though the number of passwords can be increased more than 256 kindsvoid CodeExorLong(char finame[],char foname[],char key[]) { FILE *fi,*fo; int value,i = 0; fi = fopen(finame,"rb"); if (fi == NULL) return; fo = fopen(foname,"wb"); if (fo == NULL) return; while ((value = getc(fi)) != EOF) { putc(value ^ key[i],fo); i++; if (key[i] == '\0') i = 0; } fclose(fi); fclose(fo); }
The same calculation can be easily done though the result of the exclusive-OR is seemingly random.
Because the same deal keeps being returned in the quasi-random number if an initial value is the same
Whenever an initial value is set from the password, the same calculation result is obtained.
It is simply assumed the total of the character-code value this time though the method of making an initial value from the password is various.
[ Algorithm of random numbers ]
If the compiler is different, the random numbers algorithm of a standard library is also different.
Therefore, the numerical result is different in a different compiler.
It is necessary to make the algorithm of random numbers for myself to prevent this.
[ Directions ]
CodeExorRandom (input file name, output file name, and password character string);
- The password can specify the character string of arbitrary length.
- It is possible to decode by the same password.
It is necessary to analyze the computational method of random numbers to decipher this, and it is impossible for the amateur.int GetRandom(int min,int max) { return min + (int)(rand()*(max-min+1.0)/(1.0+RAND_MAX)); } void CodeExorRandom(char finame[],char foname[],char key[]) { FILE *fi,*fo; int value,early = 0,i; fi = fopen(finame,"rb"); if (fi == NULL) return; fo = fopen(foname,"wb"); if (fo == NULL) return; for (i = 0;key[i] != '\0';i++) { early += key[i]; } srand(early); i = 0; while ((value = getc(fi)) != EOF) { putc(value ^ GetRandom(0,255),fo); i++; if (key[i] == '\0') i = 0; } fclose(fi); fclose(fo); }
[ Practical use degree of this encryption ]
If both of the encryption shown here become the natures by the simple expedient, it is possible to decipher it.
However, the amount operation can be high-speed, and easily make the program.
If it is extent built into the save data of the self-made game, it is very practicable.
The save data might be able to be remodeled easily even in a game on the market though it is a bytalk.
Especially, the nymph system game : the system save data Only bury it with 0xFF.
There is what comes for both CG and the recollection to be shown easily a lot, too.
The company is encrypted like the programmer and this, etc.