49 lines
962 B
C#
49 lines
962 B
C#
using Tiger.Utils;
|
|
|
|
namespace Tiger.Security;
|
|
|
|
public static class HabboEncryption
|
|
{
|
|
public static string GenerateKey()
|
|
{
|
|
var key = string.Empty;
|
|
for (var i = 0; i < 4; i++)
|
|
{
|
|
key += SafeRandomizer.Between(0, 255).ToString("X");
|
|
}
|
|
|
|
return key;
|
|
}
|
|
|
|
public static int DecodeKey(string key)
|
|
{
|
|
var tTable = key[..(key.Length / 2)];
|
|
var tKey = key[(key.Length / 2)..];
|
|
var checksum = 0;
|
|
|
|
for (var i = 0; i < tTable.Length; i++)
|
|
{
|
|
var a = tTable.IndexOf(tKey[i]);
|
|
|
|
if (a % 2 == 0)
|
|
{
|
|
a *= 2;
|
|
}
|
|
|
|
if (i % 3 == 0)
|
|
{
|
|
a *= 3;
|
|
}
|
|
|
|
if (a < 0)
|
|
{
|
|
a = tTable.Length % 2;
|
|
}
|
|
|
|
checksum += a;
|
|
checksum ^= a << (i % 3) * 8;
|
|
}
|
|
|
|
return checksum;
|
|
}
|
|
} |