ctr_Repair/trunk/MakeMasterKey/src/MakeMasterKeyForCtr.cpp
N1363 0884e17a8e ペアレンタルコントロール解除用マスターキー生成ツール追加。
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@755 385bec56-5757-e545-9c3a-d8741f4650f1
2013-10-25 00:10:37 +00:00

96 lines
2.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdio.h>
#include <stdlib.h>
#define CODE_LENGTH 8
typedef unsigned char u8;
typedef unsigned short int u16;
typedef unsigned long u32;
typedef unsigned long long int u64;
typedef signed char s8;
typedef signed short int s16;
typedef signed long s32;
u32 table[0x100];
//==========================================================================
//
//==========================================================================
void _Crc32Init( void )
{
u32 poly = 0xedba6320; // DSÌÆ« 0xedb88320;
u32 crc;
for( u32 i = 0; i < 0x100; i++ )
{
crc = i;
for( u32 j = 8; j > 0; j-- )
{
if( crc & 1 )
{
crc = (crc>>1)^poly;
}
else
{
crc >>= 1;
}
}
table[i] = crc;
}
}
//==========================================================================
//
//==========================================================================
u32 _CalcCrc32( const u8 *src, u32 len )
{
u32 crc = 0xffffffff;
while( len )
{
crc = ((crc>>8)&0xffffffff)^table[(crc^(*src))&0xff];
src++;
len--;
}
return crc;
}
//==========================================================================
//
//==========================================================================
u32 _CalcMasterkey( const u8 *src )
{
u32 key;
_Crc32Init();
//key = ((_CalcCrc32( src, CODE_LENGTH )^0xaaaa)+5313)%100000;
key = ((_CalcCrc32( src, CODE_LENGTH )^0xaaaa)+5719)%100000;
return key;
}
//==========================================================================
//
//==========================================================================
int main( int argc, char *argv[] )
{
u32 masterKey;
if ( ( argc != 2 ) || ( argv[1] == NULL ) )
{
printf( "usage: MakeMasterKeyForCtr [date+code]\n" );
printf( "\n" );
printf( "example: date = Sep 8. code = 1234\n" );
printf( " MakeMasterKeyForCtr 09081234\n" );
return 1;
}
masterKey = _CalcMasterkey( (const u8*)argv[1] );
printf( "Master Key = %05d\n", masterKey );
return 0;
}