Common encryption and compression algorithms for Japanese games

Source: Internet
Author: User

Normally, you will see the following information:
Program Cracker:
Analysis of game encryption methods, the ability to write basic file unpacking tools and packaging tools, the ability to extract, restore and edit encrypted game text. Familiar with assembly and disassembly and a familiar programming language, and some common compression algorithms (such as lz777 and zlib)

Games in Japan, both PC and host, will archive and encrypt resource files other than the game framework for copyrighted purposes.

We will discuss the most common and simplest compression and encryption algorithms commonly used in Japanese games.

This is not a cryptography/compression course. If you need to learn more, buy a book.

Simple Encryption

Pseudocode: (I am too lazy to write and read the file part, write it myself)

While (! Fileend) {// traverse the file
Byte databyte = readbyte (); // read a byte
Encryption Method (encrypted content, Encrypted Key );
Writebyte (databyte); // write it to the new file
}
Encryption Method
Method 1: perform some simple operations directly:
Databyte =-databyte;
Databyte = + 1;

Method 2: XOR
Some encryption technologies I have seen so far are based on the XOR operator.
For example, if tomorrow is fine and red
If a xor B = C, c xor B = A, or c xor a = B
Of course, this is only the simplest encryption method, but this method is simple, but some people still use it. After all, the game speed is still necessary.
In addition to the XOR character, the offset address in the XOR file is also very common, such
Writing is simple:
Databyte ^ = 0xaa; // The Red encryption method XOR hex AA, and tomorrow's day is FF

Some variant XOR Methods
// Rsftrx
Static void decode_rem_shiftr_xor (byte * Buf, unsigned int Len, DWORD key)
{
Byte XOR = (byte) Key;

For (unsigned int I = 0; I <Len; I ++)
Buf [I] ^ = Key >>( I % 5 );
}

// Xror
Static void decode_xor_ror (byte * Buf, unsigned int Len, DWORD key)
{
Byte shift, XOR;

Shift = (byte) Key;
XOR = (byte) (Key> 8) & 0xff );
If (! Shift)
Shift = 15;
If (! XOR)
XOR = 0xf0;

Shift & = 7;
For (unsigned int I = 0; I <Len; I ++ ){
Buf [I] ^ = XOR;
Buf [I] = (BUF [I]> shift) | (BUF [I] <(8-shift ));
}
}

// Nxorn
Static void decode_not_xor_not (byte * Buf, unsigned int Len, DWORD key)
{
Byte XOR = (byte) Key;

For (unsigned int I = 0; I <Len; I ++)
Buf [I] = ~ (BUF [I] ^ ~ XOR );
}

// Ixorn
Static void decode_inc_xor_not (byte * Buf, unsigned int Len, DWORD key)
{
Byte XOR = (byte) Key;

For (unsigned int I = 0; I <Len; I ++)
Buf [I] = ~ (BUF [I] ^ (XOR + 1 ));
}

// Xorinc
Static void decode_xor_inc (byte * Buf, unsigned int Len, DWORD key)
{
Byte XOR = (byte) Key;

For (unsigned int I = 0; I <Len; I ++)
Buf [I] = (BUF [I] ^ 0xaf) + 1;
}

// Sftrx
Static void decode_shiftr_xor (byte * Buf, unsigned int Len, DWORD key)
{
For (unsigned int I = 0; I <Len; I ++)
Buf [I] = Buf [I] ^ (byte) (Key> 3 );
}

Crypto checker
A simple command line tool is used to analyze the encryption algorithm used by the program.

The following describes the existing code on the encrypted network.
. Net Java has a ready-made class library. If it is unclear how to use it to check Baidu

MD5 Encryption
Ego Yamoto Dama's later game script uses MD5 Encryption
Simply put, a function compresses messages of any length to a fixed-length message digest. The key function is often used in the game to quickly locate the location of the data to be read in the resource file.
Http://baike.baidu.com/view/604021.htm

Blowfish Encryption
Blowfish is one of the symmetric encryption algorithms. Unlike the one-way hash function described earlier, blowfish's encrypted data is reversible. Because blowfish is fast in encryption/decryption, more importantly, no copyright fee is required for free use, many games use blowfish to encrypt resource file data.
For example, Ef-the first tale.
About: http://baike.baidu.com/view/2208941.htm

CRC
Strictly speaking, CRC is not an encryption method. It is a verification method to prevent you from modifying its contents.
Many game patches, such as C3 1.10patch, have CRC.
About: http://baike.baidu.com/view/80377.htm

Compressed part
Most commercial games do not store image resources in common formats that can be opened directly, but compress them. There are two advantages: first, images cannot be directly modified by users or used for other purposes. Second, the disk space occupied by game image resources is reduced.

There are many compression algorithms. Which one is better? You will surely think of the common JPEG and GIF formats on webpages, but these two algorithms are not suitable for use in games. For game development, we must choose an algorithm with high compression ratio and fast decoding speed. If the JPEG lossless compression algorithm is used, the compression rate is not high. If lossy compression is used, although the compression rate is high, the image in the game cannot be damaged. Also, the biggest drawback of the JPEG algorithm is that the decoding speed is too slow. The GIF algorithm has a high performance and a high compression rate and fast decoding. Unfortunately, it cannot compress images of more than 256 colors. However, if your game is made in 256 colors, it would be better to use the GIF algorithm.
General Games use PNG and BMP
PNG adopts a zlib compression algorithm.

Lz77, Huffman, LZW, and RLE are all classic compression algorithms ~
Ready-made code on the network

I met
Huffman compression algorithm
This is used by the wandering soul.
Huffman + LZW algorithm

In general, the two most common games in Japan are lzss and zlib.

Lzss
Http://zh.wikipedia.org/zh-cn/LZ77%E4%B8%8ELZ78
Http://en.wikipedia.org/wiki/LZSS
Example of lzss implementation:
Previously Used compress.exe/expand.exe
The compression algorithm used in the BIOS of GBA is lz77's variant algorithm lzss.

Here we will give you a library for your convenience.
That is, nds gba built-in algorithm http://download.csdn.net/source/1425147
Note that lzss lz77 has many variant algorithms, such as lzss + Huffman.

Zlib
Http://baike.baidu.com/view/2258413.htm
Obtain zlib
The home page of zlib is: http://www.zlib.net/
Game compressed by zlib: Sister juice
For Java
Zlib is already encoded as part of the Java sdk in the java.util.zip package
C # You can use this:
Http://blog.csdn.net/luozhuang/archive/2008/11/30/3415669.aspx

Zip Compression
This should be uncommon, but not nobody uses Battlefield 2 or zip (11 game gets to that country)
C # No class library with zip Compression
There are several methods:
1. Use icsharpcode. sharpziplib, a foreign open-source pressurized decompression library. The official website of this library is
Http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx
2. Use WinRAR
WinRAR has a command line tool. This method is used by a famous company in China, but it is compressed in the RAR format.
3
Http://dotnetzip.codeplex.com/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.