※スタイルシート未対応ブラウザではレイアウトを正確に再現できません。
  < The returning  contents  advance >   
                   < [modosusu] > Color magazine monochrome light and shade   font predetermined, Gothic Ming-style type longhand   size Konaka large   standard  


  Caesar and exclusive-OR method   

  1. ..clause 1..: What is the encryption?
  2. ..clause 2..: Caesar code
  3. ..clause 3..: Exclusive-OR code
  4. ..clause 4..: Long password
  5. ..clause 5..: Application of quasi-random number

[1] What is the encryption?

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 returns to contents.


[2] Caesar code

It is said that it is famous Caesar (cesarean) that used the code for the first time in the world.
The method only moves the character by several characters by an extremely simple method.

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.
 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);

}
If differences with former data are compared, this code is easily deciphered.

It returns to contents.


[3] Exclusive-OR code

The Caesar code is easily deciphered because it is simple.
Then, use the exclusive-OR to make it to cramped a little more.


[   Exclusive-OR   ]
When the same number is input by calculating the binary number, the output becomes 0.
It is suitable for the encryption because it becomes a random on the face of things numerical value in the exclusive-OR.
Use ^ sign to calculate the exclusive-OR by C language.

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.
 void 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);

}
Though this code is never deciphered only by glancing
If 256 kinds of passwords are tested, it is deciphered. (If it is a computer, it is moment. )

It returns to contents.


[4] Long password

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.
 void 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);

}
As a result, though the number of passwords can be increased more than 256 kinds
The password of about several characters is deciphered when thinking about the performance of a present computer.

It returns to contents.


[5] Application of quasi-random number

The same calculation can be easily done though the result of the exclusive-OR is seemingly random.
Prevent the content of the calculation being understood by using the quasi-random number to prevent this.

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.


[ 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.
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.
The following program applies this to a general binary file.
[   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.
 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);

}
It is necessary to analyze the computational method of random numbers to decipher this, and it is impossible for the amateur.
However, if a person well informed becomes the nature as such, it is likely to be deciphered.

[ 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.

It returns to contents.


< - Advanced -> to the returning following. the first  that returns