📄 zalgo.cpp
字号:
// This is the C++ port of D2Emu's z_algo.pas V0.01
// SilentPeace
#include <iostream.h>
#include <conio.h>
#include <memory.h>
#define SHORT unsigned int
const SHORT CryptTable[256]=
{0xDA,0x26,0xE8,0x72,0x11,0x52,0x3E,0x46,0x32,0xFF,0x8C,0x1E,0xA7,0xBE,0x2C,0x29,
0x5F,0x86,0x7E,0x75,0x0A,0x08,0xA5,0x21,0x61,0xFB,0x7A,0x58,0x60,0xF7,0x81,0x4F,
0xE4,0xFC,0xDF,0xB1,0xBB,0x6A,0x02,0xB3,0x0B,0x6E,0x5D,0x5C,0xD5,0xCF,0xCA,0x2A,
0x14,0xB7,0x90,0xF3,0xD9,0x37,0x3A,0x59,0x44,0x69,0xC9,0x78,0x30,0x16,0x39,0x9A,
0x0D,0x05,0x1F,0x8B,0x5E,0xEE,0x1B,0xC4,0x76,0x43,0xBD,0xEB,0x42,0xEF,0xF9,0xD0,
0x4D,0xE3,0xF4,0x57,0x56,0xA3,0x0F,0xA6,0x50,0xFD,0xDE,0xD2,0x80,0x4C,0xD3,0xCB,
0xF8,0x49,0x8F,0x22,0x71,0x84,0x33,0xE0,0x47,0xC2,0x93,0xBC,0x7C,0x3B,0x9C,0x7D,
0xEC,0xC3,0xF1,0x89,0xCE,0x98,0xA2,0xE1,0xC1,0xF2,0x27,0x12,0x01,0xEA,0xE5,0x9B,
0x25,0x87,0x96,0x7B,0x34,0x45,0xAD,0xD1,0xB5,0xDB,0x83,0x55,0xB0,0x9E,0x19,0xD7,
0x17,0xC6,0x35,0xD8,0xF0,0xAE,0xD4,0x2B,0x1D,0xA0,0x99,0x8A,0x15,0x00,0xAF,0x2D,
0x09,0xA8,0xF5,0x6C,0xA1,0x63,0x67,0x51,0x3C,0xB2,0xC0,0xED,0x94,0x03,0x6F,0xBA,
0x3F,0x4E,0x62,0x92,0x85,0xDD,0xAB,0xFE,0x10,0x2E,0x68,0x65,0xE7,0x04,0xF6,0x0C,
0x20,0x1C,0xA9,0x53,0x40,0x77,0x2F,0xA4,0xFA,0x6D,0x73,0x28,0xE2,0xCD,0x79,0xC8,
0x97,0x66,0x8E,0x82,0x74,0x06,0xC7,0x88,0x1A,0x4A,0x6B,0xCC,0x41,0xE9,0x9D,0xB8,
0x23,0x9F,0x3D,0xBF,0x8D,0x95,0xC5,0x13,0xB9,0x24,0x5A,0xDC,0x64,0x18,0x38,0x91,
0x7F,0x5B,0x70,0x54,0x07,0xB6,0x4B,0x0E,0x36,0xAC,0x31,0xE6,0xD6,0x48,0xAA,0xB4};
// Test String
// 01 02 09..3C 96 1F..
const SHORT Tstr[64] =
{0x3C,0x96,0x1F,0xC0,0x2B,0x3E,0xA9,0x5B,0xDE,0xF0,0x49,0x8C,0x7C,0xA0,0xF1,0xE6,
0x88,0xE0,0x1D,0xA8,0xA8,0x5C,0x0C,0x64,0x6E,0x71,0x3B,0xDF,0x67,0xE7,0x05,0xF1,
0xE4,0xC7,0x65,0xDF,0x0D,0xF9,0x13,0x5C,0xC9,0x57,0x1A,0x74,0x75,0x0D,0xC2,0x6A,
0x76,0x7C,0xF1,0x6A,0x3A,0x5E,0xDB,0x92,0x1A,0xB9,0x12,0x98,0x44,0xE1,0x7A,0x83};
// Cardfile 0
const SHORT Card0[64] =
{0x06,0x66,0x66,0x66,0x62,0x7C,0xB6,0xAA,0xB8,0x37,0x30,0x59,0xAC,0x85,0xF6,0xFF,
0x0C,0x75,0x87,0xDB,0x75,0xFA,0xEA,0x06,0x03,0xFB,0xDC,0x49,0x84,0x8D,0x08,0x34,
0xB3,0x00,0x88,0x7A,0x8A,0x61,0xDE,0xB5,0x4B,0xD9,0x4B,0xAF,0x2A,0x6E,0x46,0x44,
0x9E,0x4D,0x5F,0xE4,0x71,0x5B,0x04,0xAC,0x3F,0x96,0x23,0x25,0xB6,0x98,0x18,0xBD};
// Cardfile 1
const SHORT Card1[64] =
{0x00,0x00,0x00,0x00,0x9C,0x83,0x75,0x53,0x37,0x60,0x71,0xFD,0x0B,0x11,0x68,0x26,
0x0D,0xA2,0xC5,0xB5,0x90,0xCB,0x6F,0x0F,0x60,0xA5,0x94,0x83,0x49,0xF6,0xB7,0xC2,
0x07,0xBF,0x10,0xFE,0x7D,0xC9,0x58,0x93,0x9B,0x60,0xFB,0x7D,0xB0,0x72,0xD9,0x5A,
0x34,0x30,0x83,0x25,0x0F,0x94,0x8F,0x44,0x5F,0x73,0x96,0x97,0xD2,0x66,0xC1,0x17};
const int BUFSIZE64 = 64 * sizeof(SHORT);
const int BUFSIZE128 = 128 * sizeof(SHORT);
SHORT Ergebnis[129];
SHORT erg0[64];
SHORT erg1[64];
SHORT erg2[64];
SHORT erg3[64];
SHORT erg4[128];
SHORT card1Z[64];
//---------------------------------------------
void x_mal_y(SHORT X_Var[], SHORT Y_Var[])
{
int i, j, f;
long x;
memset(Ergebnis, 0, BUFSIZE128);
for(j = 0; j<64; ++j)
{
for(i = 0; i<64; ++i)
{
x = (X_Var[i] * Y_Var[j]);
f = x % 256;
Ergebnis[i + j] += f;
if(Ergebnis[i + j] > 0xFF)
{
Ergebnis[i + j] -= 256;
++(Ergebnis[i + j + 1]);
}
Ergebnis[i + j + 1] += (x >> 8);
if(Ergebnis[i + j + 1] > 0xFF)
{
Ergebnis[i + j + 1] -= 256;
++(Ergebnis[i + j + 2]);
if(Ergebnis[i + j + 2] > 0xFF)
{
Ergebnis[i + j + 2] -= 256;
++(Ergebnis[i + j + 3]);
if(Ergebnis[i + j + 3] > 0xFF)
{
Ergebnis[i + j + 3] -=256;
++(Ergebnis[i + j + 4]);
}
}
}
}
}
for(j = 63; j>= 0; --j)
{
for(i = 0; i<60; ++i)
{
x = (card1Z[i] * Ergebnis[j+64]);
f = x % 256;
Ergebnis[i + j] += f;
if(Ergebnis[i + j] > 0xFF)
{
Ergebnis[i + j] -= 256;
++(Ergebnis[i + j + 1]);
}
Ergebnis[i + j + 1] += (x >> 8);
if(Ergebnis[i + j + 1] > 0xFF)
{
Ergebnis[i + j + 1] -= 256;
++(Ergebnis[i + j + 2]);
if(Ergebnis[i + j + 2] > 0xFF)
{
Ergebnis[i + j + 2] -= 256;
++(Ergebnis[i + j + 3]);
if(Ergebnis[i + j + 3] > 0xFF)
{
Ergebnis[i + j + 3] -= 256;
++(Ergebnis[i + j + 4]);
}
}
}
}
}
}
//----------------------------------------
void output()
{
for(int l = 0; l<16; ++l)
{
for(int k = 0; k<8; ++k)
{
cout.flags(ios::hex|ios::uppercase);
cout.width(2);
cout.fill('0');
cout<<Ergebnis[k+(l*8)]<<" ";
}
cout<<endl;
}
}
//----------------------------------------
void output2()
{
for(int l = 0; l<4; ++l)
{
for(int k = 0; k<16; ++k)
{
cout.flags(ios::hex|ios::uppercase);
cout.width(2);
cout.fill('0');
cout<<erg3[k+(l*16)]<<" ";
}
cout<<endl;
}
}
//----------------------------------------
void output3()
{
cout<<"Mein berechnetes Ergebnis: ";
for(int k = 0; k<8; ++k)
{
cout.flags(ios::hex|ios::uppercase);
cout.width(2);
cout.fill('0');
cout<<erg4[k+24]<<" ";
}
cout<<endl;
}
//----------------------------------------
void output4()
{
cout<<"Mein berechneter Camkey: ";
for(int k = 0; k<8; ++k)
{
cout.flags(ios::hex|ios::uppercase);
cout.width(2);
cout.fill('0');
cout<<erg4[k+8]<<" ";
}
cout<<endl;
}
//-----------------Hauptprogram-----------
int main(int argc, char* argv[])
{
cout<<"Rechne..."<<endl;
//----------------------------------------
//-String vom CAM in erg0 speichern-
//-Low ist hinten deswegen drehen-
for(int i = 0; i<64; ++i)
{
erg0[i] = Tstr[63-i];
}
//-Cardfile speichern-
//-Low ist hinten deswegen drehen-
for(i = 0; i<64; ++i)
{
card1Z[i] = Card1[63-i];
}
//----------------------------------------
//-String vom CAM ^ 2 in erg1 speichern-
//-inklusive Z-Kodierung-
x_mal_y(erg0, erg0);
memcpy(erg1, Ergebnis, BUFSIZE64);
//----------------------------------------
//-String vom CAM ^ 4 in erg2 speichern-
//-inklusive Z-Kodierung-
x_mal_y(erg1, erg0);
memcpy(erg2, Ergebnis, BUFSIZE64);
//----------------------------------------
//-Den Wert 1 fuer die weitere Berechnung laden-
memset(erg3, 0, BUFSIZE64);
erg3[0] = 1;
//----------------------------------------
SHORT h;
int s, t;
for(int r = 0; r < 64; ++r)
{
h = Card0[r];
s = 4;
//-F黨rende Nullen ausblenden-
if(!r)
{
if((s == 4) && (!(h & 0xC0)))
{
s = 3;
}
if((s == 3) && (!(h & 0x30)))
{
s = 2;
}
if((s == 2) && (!(h & 0x0C)))
{
s = 1;
}
}
do
{
t = (s-1) * 2;
t = h >> t;
t = t & 0x03;
//-1.mal---------------------------------------
//- Ergebnis ^ 2 -
x_mal_y(erg3, erg3);
memcpy(erg3, Ergebnis, BUFSIZE64);
//-2.mal---------------------------------------
//- Ergebnis ^ 4 -
x_mal_y(erg3,erg3);
memcpy(erg3, Ergebnis, BUFSIZE64);
if(t != 0)
{
//- Bitpaar auswerten und mal Cam, Cam^2 oder Cam^4 nehmen
//-3.mal---------------------------------------
--t;
if(!t)
{
x_mal_y(erg3, erg0);
}
if(t == 1)
{
x_mal_y(erg3, erg1);
}
if(t == 2)
{
x_mal_y(erg3, erg2);
}
memcpy(erg3, Ergebnis, BUFSIZE64);
//----------------------------------------
}
--s;
}
while(s > 0);
}
//-Ergbnis umdrehen nach erg4-------------
for(i = 0; i<64; ++i)
{
erg4[63-i] = erg3[i];
}
//-7 mal nach links shiften (8 Byte)------
for(i = 0; i<7; ++i)
{
erg4[0+16] <<= 1;
erg4[1+16] <<= 1;
erg4[2+16] <<= 1;
erg4[3+16] <<= 1;
erg4[4+16] <<= 1;
erg4[5+16] <<= 1;
erg4[6+16] <<= 1;
erg4[7+16] <<= 1;
if(erg4[7+16] > 0xFF)
{
++(erg4[0+16]);
}
if(erg4[7+16] > 0xFF)
{
erg4[7+16] -= 256;
}
if(erg4[6+16] > 0xFF)
{
++(erg4[7+16]);
}
if(erg4[6+16] > 0xFF)
{
erg4[6+16] -= 256;
}
if(erg4[5+16] > 0xFF)
{
++(erg4[6+16]);
}
if(erg4[5+16] > 0xFF)
{
erg4[5+16] -= 256;
}
if(erg4[4+16] > 0xFF)
{
++(erg4[5+16]);
}
if(erg4[4+16] > 0xFF)
{
erg4[4+16] -= 256;
}
if(erg4[3+16] > 0xFF)
{
++(erg4[4+16]);
}
if(erg4[3+16] > 0xFF)
{
erg4[3+16] -= 256;
}
if(erg4[2+16] > 0xFF)
{
++(erg4[3+16]);
}
if(erg4[2+16] > 0xFF)
{
erg4[2+16] -= 256;
}
if(erg4[1+16] > 0xFF)
{
++(erg4[2+16]);
}
if(erg4[1+16] > 0xFF)
{
erg4[1+16] -= 256;
}
if(erg4[0+16] > 0xFF)
{
++(erg4[1+16]);
}
if(erg4[0+16] > 0xFF)
{
erg4[0+16] -= 256;
}
}
//-Verschluesseln mit Crypt Tabelle-------
int u;
for(int j = 7; j>= 0; --j)
{
for(i = 7; i>= 0; --i)
{
r = erg4[24+6];
s = erg4[16+i] ^ r;
s ^= j;
t = CryptTable[s];
u = erg4[24];
s = erg4[24+7];
s ^= t;
erg4[24]= s;
erg4[24+7] = r;
s = erg4[24+5];
s ^= t;
erg4[24+6] = s;
s = erg4[24+4];
erg4[24+5] = s;
s = erg4[24+3];
erg4[24+4] = s;
s = erg4[24+2];
erg4[24+3] = s;
s = erg4[24+1];
erg4[24+2] = s;
erg4[24+1] = u;
}
//- 1 Stelle nach rechts shiften -
if(erg4[0+16] & 1)
{
erg4[7+16] += 256;
}
if(erg4[7+16] & 1)
{
erg4[6+16] += 256;
}
if(erg4[6+16] & 1)
{
erg4[5+16] += 256;
}
if(erg4[5+16] & 1)
{
erg4[4+16] += 256;
}
if(erg4[4+16] & 1)
{
erg4[3+16] += 256;
}
if(erg4[3+16] & 1)
{
erg4[2+16] += 256;
}
if(erg4[2+16] & 1)
{
erg4[1+16] += 256;
}
if(erg4[1+16] & 1)
{
erg4[0+16] += 256;
}
erg4[0+16] >>= 1;
erg4[1+16] >>= 1;
erg4[2+16] >>= 1;
erg4[3+16] >>= 1;
erg4[4+16] >>= 1;
erg4[5+16] >>= 1;
erg4[6+16] >>= 1;
erg4[7+16] >>= 1;
}
//-Fertig---------------------------------
output3();
output4();
cout<<"\nRichtige Antwort auf 010209: 97 A4 58 3D 24 0D EB E0"<<endl;
getch();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -