Difference between revisions of "Cryptography"
Line 34: | Line 34: | ||
} | } | ||
return 32769 * (9 * retHash ^ (9 * retHash >> 11)); | return 32769 * (9 * retHash ^ (9 * retHash >> 11)); | ||
+ | }</source> | ||
+ | |||
+ | As you can see it differs from most common hashing algorithms in the way it handles text (by not including " or \ characters). | ||
+ | |||
+ | ===One At A Time Hash=== | ||
+ | |||
+ | The One At A Time hashing function was originally created by Bob Jenkins. A C++ implementation can be found here and at [[Wikipedia:Hash_table#Choosing_a_good_hash_function|Wikipedia]]. | ||
+ | |||
+ | <source lang="cpp">unsigned int oneAtATimeHash(char* inpStr) | ||
+ | { | ||
+ | unsigned int value = 0,temp = 0; | ||
+ | for(size_t i=0;i<strlen(inpStr);i++) | ||
+ | { | ||
+ | char ctext = tolower(inpStr[i]); | ||
+ | temp = hashchr; | ||
+ | temp += value; | ||
+ | value = temp << 10; | ||
+ | temp += value; | ||
+ | value = temp >> 6; | ||
+ | value ^= temp; | ||
+ | } | ||
+ | temp = value << 3; | ||
+ | temp += value; | ||
+ | unsigned int temp2 = temp >> 11; | ||
+ | temp = temp2 ^ temp; | ||
+ | temp2 = temp << 15; | ||
+ | value = temp2 + temp; | ||
+ | if(value < 2) value += 2; | ||
+ | return value; | ||
}</source> | }</source> | ||
Revision as of 08:48, 15 February 2009
This article explains the Cryptography present in GTA IV.
Hash Algorithms
GTA IV relies on many different hash algorithms work its operation, each for a different purpose. GTA IV's new usage of hashing has allowed it to explore a more binary focused way of hiding data in files, and strings away from plain site.
SHA1
The SHA1 hashing algorithm is used when comparing the files in versions 1.0 and 1.0.1. This check was later removed in 1.0.2.
CRC32
The Cyclic Redundancy Check 32 bit hashing algorithm is used in the GXT file to match text codes with their counterparts. A C++ implementation of GTA IV's CRC32 Hashing Algorithm can be displayed as follows:
unsigned int CRC32(char* text)
{
size_t textLen = strlen(text);
int i = 0;
unsigned int retHash = 0;
if(text[0] == '"')
i = 1;
for(i;i<textLen;i++)
{
char ctext = textLen[i];
if(ctext == '"')
break;
if(ctext - 65 > 25)
{
if(ctext == '\\')
ctext = '/';
}
else ctext += 32;
retHash = (1025 * (retHash + ctext) >> 6) ^ 1025 * (retHash + ctext);
}
return 32769 * (9 * retHash ^ (9 * retHash >> 11));
}
As you can see it differs from most common hashing algorithms in the way it handles text (by not including " or \ characters).
One At A Time Hash
The One At A Time hashing function was originally created by Bob Jenkins. A C++ implementation can be found here and at Wikipedia.
unsigned int oneAtATimeHash(char* inpStr)
{
unsigned int value = 0,temp = 0;
for(size_t i=0;i<strlen(inpStr);i++)
{
char ctext = tolower(inpStr[i]);
temp = hashchr;
temp += value;
value = temp << 10;
temp += value;
value = temp >> 6;
value ^= temp;
}
temp = value << 3;
temp += value;
unsigned int temp2 = temp >> 11;
temp = temp2 ^ temp;
temp2 = temp << 15;
value = temp2 + temp;
if(value < 2) value += 2;
return value;
}
Grand Theft Auto IV | |
---|---|
File Formats | .dat • .gxt • .ide • .img • .ipl • .nod • .sco • .rpf • .rrr • .wad • .wbd/.wbn • .wdd • .wdr • .wft • .whm • .wpl • .wtd |
Documentation | Audio • Bink Video • Cryptography • Cutscenes • GXT Text • Image listing • Keycodes • Map Listing • Native functions • Paths • Radar Blips • Radio Stations • Saves • Scenarios • VTable • Weapons |
Tools | ASI Loader • ENBSeries • G-Texture • GIMS IV • Ingame WPL Editor • IV Needle • OpenIV • SparkIV • XLiveLess • WPL Manager • X Mod Installer Alice • C++ Script Hook • .NET Script Hook • Scocl |
Tutorials | Importing Textures with OpenIV • Importing Textures with SparkIV |
Modifications | GTA Connected • Gostown IV • Four Multiplayer • IV Multiplayer • CitizenMP:IV Reloaded |
Useful links | Community portal • Discussion forums • Modding forums • Mods on GTAGarage.com |