22 public static byte[]
DeriveNormalKey(ReadOnlySpan<byte> keyX, ReadOnlySpan<byte> keyY)
24 ValidateKey(keyX, nameof(keyX));
25 ValidateKey(keyY, nameof(keyY));
26 Span<byte> sum = stackalloc
byte[16];
28 for (
int index = 0; index < sum.Length; index++)
30 int value = (keyX[index] ^ keyY[index]) + ScramblerConstant[^(index + 1)] + carry;
31 sum[index] = (byte)value;
35 return RotateLeft(sum, 42);
46 ArgumentNullException.ThrowIfNull(gameCode);
47 if (gameCode.Length != 4 || gameCode.Any(
static value => value is <
' ' or >
'~'))
49 throw new ArgumentException(
"A modcrypt game code must contain exactly four printable ASCII characters.", nameof(gameCode));
52 var keyX =
new byte[16];
53 "Nintendo"u8.CopyTo(keyX);
54 Encoding.ASCII.GetBytes(gameCode, keyX.AsSpan(8, 4));
55 for (
int index = 0; index < 4; index++)
57 keyX[12 + index] = keyX[11 - index];