ASP.NET Razor website for https://wotdn.nightmare.haus
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.2 KiB
71 lines
2.2 KiB
3 years ago
|
/*
|
||
|
* Copyright (C) 2012-2020 CypherCore <http://github.com/CypherCore>
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation, either version 3 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
namespace System
|
||
|
{
|
||
|
public static class Extensions
|
||
|
{
|
||
|
static uint LeftRotate(this uint value, int shiftCount)
|
||
|
{
|
||
|
return (value << shiftCount) | (value >> (0x20 - shiftCount));
|
||
|
}
|
||
|
|
||
|
public static byte[] GenerateRandomKey(this byte[] s, int length)
|
||
|
{
|
||
|
var random = new Random((int)((uint)(Guid.NewGuid().GetHashCode() ^ 1 >> 89 << 2 ^ 42)).LeftRotate(13));
|
||
|
var key = new byte[length];
|
||
|
|
||
|
for (int i = 0; i < length; i++)
|
||
|
{
|
||
|
int randValue;
|
||
|
|
||
|
do
|
||
|
{
|
||
|
randValue = (int)((uint)random.Next(0xFF)).LeftRotate(1) ^ i;
|
||
|
} while (randValue > 0xFF && randValue <= 0);
|
||
|
|
||
|
key[i] = (byte)randValue;
|
||
|
}
|
||
|
|
||
|
return key;
|
||
|
}
|
||
|
|
||
|
public static bool Compare(this byte[] b, byte[] b2)
|
||
|
{
|
||
|
for (int i = 0; i < b2.Length; i++)
|
||
|
if (b[i] != b2[i])
|
||
|
return false;
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
public static byte[] Combine(this byte[] data, params byte[][] pData)
|
||
|
{
|
||
|
var combined = data;
|
||
|
|
||
|
foreach (var arr in pData)
|
||
|
{
|
||
|
var currentSize = combined.Length;
|
||
|
|
||
|
Array.Resize(ref combined, currentSize + arr.Length);
|
||
|
|
||
|
Buffer.BlockCopy(arr, 0, combined, currentSize, arr.Length);
|
||
|
}
|
||
|
|
||
|
return combined;
|
||
|
}
|
||
|
}
|
||
|
}
|