本文整理汇总了C#中FastRandom.NextBytes方法的典型用法代码示例。如果您正苦于以下问题:C# FastRandom.NextBytes方法的具体用法?C# FastRandom.NextBytes怎么用?C# FastRandom.NextBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FastRandom
的用法示例。
在下文中一共展示了FastRandom.NextBytes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MsgKeepAlive
public MsgKeepAlive()
: base()
{
FastRandom fastRand = new FastRandom();
this.Payload = new byte[fastRand.Next(32, 256)];
fastRand.NextBytes(this.Payload);
}
示例2: KeyExtender
private byte[] KeyExtender(byte[] Input, int TargetLen)
{
int temp = 0xFF28423;
for (int i = 0; i < Input.Length; i++)
temp += Input[i];
int oldLen = Input.Length;
FastRandom rnd = new FastRandom(temp);
Array.Resize(ref Input, TargetLen);
rnd.NextBytes(Input, oldLen, TargetLen);
return Input;
}
示例3: IsAlgorithmWeak
/// <summary>
/// Agressively scan the algorithm for weakness
/// </summary>
/// <param name="EncryptCode"></param>
/// <param name="DecryptCode"></param>
/// <returns></returns>
private static bool IsAlgorithmWeak(byte[] EncryptCode, byte[] DecryptCode, int Seed)
{
FastRandom rnd = new FastRandom(Seed);
byte[] RandData = new byte[513];
rnd.NextBytes(RandData);
byte[] Key = new byte[] { 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5 };
byte[] Salt = new byte[] { 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1 };
byte[] IV = new byte[] { 100, 132, 194, 103, 165, 222, 64, 110, 144, 217, 202, 129, 54, 97, 230, 25, 34, 58, 100, 79, 80, 124, 14, 61, 191, 5, 174, 94, 194, 10, 222, 215 };
WopEx wop = new WopEx(Key, Salt, IV, EncryptCode, DecryptCode, WopEncMode.Simple, 1, true);
//test it 50 times if it's safe to use
for (int x = 0; x < 50; x++)
{
byte[] crypted = new byte[RandData.Length];
Array.Copy(RandData, crypted, RandData.Length);
wop.Encrypt(crypted, 0, crypted.Length);
double Equals = 0;
for (int i = 0; i < crypted.Length; i++)
{
if (RandData[i] == crypted[i])
{
Equals++;
}
}
wop.Decrypt(crypted, 0, crypted.Length);
//check if decryption went successful
if (RandData.Length != crypted.Length)
return true;
for (int i = 0; i < RandData.Length; i++)
{
if (RandData[i] != crypted[i])
{
//the decryption-routine failed
return true;
}
}
double Pertentage = (Equals / (double)RandData.Length) * 100D;
bool isWeak = Pertentage > 5; //if >5 % is the same as original it's a weak algorithm
if (isWeak)
return true;
}
return false;
}
示例4: ExpandKey
/// <summary>
/// A dirty way to expand a key, need to find a more clean solution
/// </summary>
private byte[] ExpandKey(byte[] input)
{
if (input.Length > KEY_SIZE)
return input;
int OrgLen = input.Length;
Array.Resize(ref input, KEY_SIZE);
FastRandom rnd = new FastRandom(BitConverter.ToInt32(input, 0));
const int BlockSize = 124;
for (int i = OrgLen, j = 5; i < KEY_SIZE; i += BlockSize, j += 32)
{
int len = i + BlockSize < KEY_SIZE ? BlockSize : KEY_SIZE - i;
rnd.NextBytes(input, i, input.Length);
rnd = new FastRandom(BitConverter.ToInt32(input, j));
}
return input;
}
示例5: GetNextRandomInstruction
private static void GetNextRandomInstruction(FastRandom rnd, ref InstructionInfo EncInstruction, ref InstructionInfo DecInstruction)
{
lock (RndInstLock)
{
Instruction[] InstructionList = new Instruction[]
{
//Instruction.BitLeft, //unstable do not use
Instruction.Minus,
Instruction.Plus,
//Instruction.ForLoop_PlusMinus,
//Instruction.RotateLeft_Big,
//Instruction.RotateLeft_Small,
Instruction.SwapBits,
Instruction.XOR
};
Instruction inst = InstructionList[rnd.Next(0, InstructionList.Length)];
switch (inst)
{
case Instruction.BitLeft:
{
int bitSize = rnd.Next(1, 3); //maybe needs to be higher ?
EncInstruction = new InstructionInfo(inst, bitSize);
DecInstruction = new InstructionInfo(Instruction.BitRight, bitSize);
break;
}
case Instruction.Minus:
{
byte[] TempDate = new byte[32];
rnd.NextBytes(TempDate);
EncInstruction = new InstructionInfo(inst, new BigInteger(TempDate));
DecInstruction = new InstructionInfo(Instruction.Plus, new BigInteger(TempDate));
break;
}
case Instruction.Plus:
{
byte[] TempDate = new byte[32];
rnd.NextBytes(TempDate);
EncInstruction = new InstructionInfo(inst, new BigInteger(TempDate));
DecInstruction = new InstructionInfo(Instruction.Minus, new BigInteger(TempDate));
break;
}
case Instruction.ForLoop_PlusMinus:
{
int size = rnd.Next();
int size2 = rnd.Next();
int loops = rnd.Next(2, 255);
EncInstruction = new InstructionInfo(inst, (uint)size, (uint)size2, loops);
DecInstruction = new InstructionInfo(inst, (uint)size, (uint)size2, loops);
break;
}
case Instruction.RotateLeft_Big:
{
byte bitSize = (byte)rnd.Next(1, 60);
EncInstruction = new InstructionInfo(inst, (uint)bitSize);
DecInstruction = new InstructionInfo(Instruction.RotateRight_Big, (uint)bitSize);
break;
}
case Instruction.RotateLeft_Small:
{
byte bitSize = (byte)rnd.Next(1, 30);
EncInstruction = new InstructionInfo(inst, (uint)bitSize);
DecInstruction = new InstructionInfo(Instruction.RotateRight_Small, (uint)bitSize);
break;
}
case Instruction.SwapBits:
{
EncInstruction = new InstructionInfo(inst, 0);
DecInstruction = new InstructionInfo(inst, 0);
break;
}
case Instruction.XOR:
{
byte[] TempDate = new byte[32];
rnd.NextBytes(TempDate);
EncInstruction = new InstructionInfo(inst, new BigInteger(TempDate));
DecInstruction = new InstructionInfo(inst, new BigInteger(TempDate));
break;
}
default: { break; }
}
}
}