本文整理汇总了C#中System.Byte.SequenceEqual方法的典型用法代码示例。如果您正苦于以下问题:C# Byte.SequenceEqual方法的具体用法?C# Byte.SequenceEqual怎么用?C# Byte.SequenceEqual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Byte
的用法示例。
在下文中一共展示了Byte.SequenceEqual方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AndroidMagicFound
/// <summary>
/// Checks the first 512 bytes for the Android magic sequence
/// </summary>
/// <param name="path"></param>
/// <param name="foundPos">The byte where the magic sequence was found.</param>
/// <returns></returns>
private static bool AndroidMagicFound(string path, out int foundPos)
{
using (var fs = new FileStream(path, FileMode.Open))
{
//fs.Seek(0, SeekOrigin.Begin);
for (var i = 0; i <= 512; i++)
{
foundPos = i;
//fs.Seek(i, SeekOrigin.Begin);
var asdf = new Byte[BootImgHeader.BootMagicSize];
fs.Read(asdf, i, BootImgHeader.BootMagicSize);
if (asdf.SequenceEqual(BootImgHeader.BootMagic))
{
Console.WriteLine("Android boot magic found");
return true;
}
}
foundPos = 0;
return false;
}
}
示例2: CompareByteArrays
public static bool CompareByteArrays(Byte[] a, Byte[] b)
{
// gleiche Länge?
if (a.Length == b.Length)
{
return a.SequenceEqual(b);
}
else
return false;
}
示例3: Each_Byte_Each_Scheme
public void Each_Byte_Each_Scheme()
{
for(var numShares = 2; numShares < 256; numShares++)
{
for(var threshold = 2; threshold <= numShares; threshold++)
{
for(var theByte = 0; theByte < 256; theByte++)
{
var secret = new Byte[1] { (byte)theByte };
var shares = _handler.Split(secret, threshold, numShares);
foreach(var permutation in GetAllPermutations(shares, threshold))
{
var restoredSecret = _handler.Restore(permutation);
Assert.IsTrue(secret.SequenceEqual(restoredSecret));
}
}
}
}
}
示例4: EncryptionDecriptionTest
public void EncryptionDecriptionTest()
{
var testVector = Utils.GetTestVector(40);
var transform = new RC4CryptoTransform(testVector.Key);
var inputBuffer = testVector.Data;
var outputBuffer = new Byte[inputBuffer.Length];
var encrypted = transform.TransformBlock(inputBuffer, 0, inputBuffer.Length, outputBuffer, 0);
Assert.AreEqual(encrypted, inputBuffer.Length);
var decryptedData = new Byte[inputBuffer.Length];
var transform2 = new RC4CryptoTransform(testVector.Key);
transform2.TransformBlock(outputBuffer, 0, outputBuffer.Length, decryptedData, 0);
Assert.IsTrue(decryptedData.SequenceEqual(inputBuffer));
}
示例5: IdentifyCategory
/// <summary>
/// Given the first few bytes of content, decide what the FileCategory
/// should be, based on what's in the Content.<br/>
/// This should be called before deciding how to set the content.
/// </summary>
/// <param name="firstBytes">At least the first four bytes of the file read in binary form - can be longer if you wish</param>
/// <returns>The type that should be used to store this file.</returns>
public static FileCategory IdentifyCategory(byte[] firstBytes)
{
var firstFour = new Byte[4];
int atMostFour = Math.Min(4, firstBytes.Length);
Array.Copy(firstBytes, 0, firstFour, 0, atMostFour);
var returnCat = (atMostFour < 4) ? FileCategory.TOOSHORT : FileCategory.OTHER; // default if none of the conditions pass
if (firstFour.SequenceEqual(CompiledObject.MagicId))
{
returnCat = FileCategory.KSM;
}
else
{
bool isAscii = firstFour.All(b => b == (byte)'\n' || b == (byte)'\t' || b == (byte)'\r' || (b >= (byte)32 && b <= (byte)127));
if (isAscii)
returnCat = FileCategory.ASCII;
}
return returnCat;
// There is not currently an explicit test for KERBOSRIPT versus other types of ASCII.
// At current, any time you want to test for is Kerboscript, make sure to test for is ASCII too,
// since nothing causes a file to become type kerboscript yet.
}
示例6: Test_Bytes
public void Test_Bytes()
{
Byte[] value = new Byte[] { 0x1, 0x2, 0x3, 0x4, 0x5 };
InformationElement infoElement = new InformationElement(
InformationElement.ElementId.VendorSpecific, value);
Byte[] ieArray = infoElement.Bytes;
Assert.AreEqual(7, ieArray.Length);
Assert.AreEqual((Byte)InformationElement.ElementId.VendorSpecific, ieArray[0]);
Assert.AreEqual(5, ieArray[1]);
Byte[] actualValue = new Byte[5];
Array.Copy(ieArray, 2, actualValue, 0, 5);
Assert.IsTrue(value.SequenceEqual(actualValue));
}
示例7: InitializeDevice
/// <summary>
/// Destructor.
/// </summary>
/*
~ADS1298device()
{
;
}
*/
/// <summary>
/// In order to initialize the device we must have a valid class guid and device path name.
/// Use FindDevice from UsbDevice to look up connected devices.
/// </summary>
///
/// <param name="devicePath"> Unique device path. </param>
///
/// <returns> True if successful. </returns>
internal override Boolean InitializeDevice(String devPath = null)
{
Byte[] configBuffer = new Byte[Marshal.SizeOf(regConfig)];
deviceConfigured = false;
processingData = true;
// Check for a valid device path.
if (devPath != null)
DevicePath = devPath;
else if ((DevicePath == null) && (devPath == null))
return false;
// Check if this devices exists.
DeviceFound = usbDev.CheckDevice(DeviceClassGuid, ref devInfo.devicePath);
if (DeviceFound)
{
// Pass the devices path name & get the device handle.
DeviceAttached = winUsbDev.GetDeviceHandle(this.DevicePath);
if (DeviceAttached)
{
// Initialize this device
DeviceAttached = winUsbDev.InitializeDevice();
if (DeviceAttached)
{
// Lets get the descriptor so we can read the product & vendor id.
DeviceAttached = winUsbDev.GetUsbDeviceDescriptor();
VendorID = winUsbDev.usbDevDescriptor.idVendor;
ProductID = winUsbDev.usbDevDescriptor.idProduct;
// Flush the pipes.
winUsbDev.FlushPipe(PIPE_COMMAND_IN);
winUsbDev.FlushPipe(PIPE_COMMAND_OUT);
winUsbDev.FlushPipe(PIPE_DATA_IN);
// Read configuration
ReadConfiguration();
while (!deviceConfigured)
{
// Let's do a double check here, save the current config & re-read it from the device
configBuffer = StructureToByteArray(ref regConfig);
ReadConfiguration();
if (configBuffer.SequenceEqual(StructureToByteArray(ref regConfig)))
deviceConfigured = true;
}
DeviceName = winUsbDev.GetUsbStringDescriptor(winUsbDev.usbDevDescriptor.iProduct);
if (String.IsNullOrEmpty(winUsbDev.GetUsbStringDescriptor(winUsbDev.usbDevDescriptor.iProduct)))
{
DeviceName = String.Concat(DeviceName,
String.Concat(Guid.NewGuid().ToString().Replace("-", "").Substring(1, 4))); // Append random numbers
}
else
DeviceName = String.Concat(DeviceName, " ", winUsbDev.GetUsbStringDescriptor(winUsbDev.usbDevDescriptor.iSerialNumber));
SampleLength = SAMPLELENGTH;
ResolutionBits = RESOLUTION;
InputDifferantialVoltagePositive = INPUT_DIFFERANTIAL_VOLTAGE_POSITIVE;
InputDifferantialVoltageNegative = INPUT_DIFFERANTIAL_VOLTAGE_NEGATIVE;
EPdeviceType = this.ToString().Substring(this.ToString().LastIndexOf(".") + 1);
}
}
else
winUsbDev.CloseDeviceHandle();
}
return (DeviceFound && DeviceAttached && deviceConfigured);
}
示例8: breakSAV
//.........这里部分代码省略.........
pkx1 = decryptArray(data1a); pkx2 = decryptArray(data2a);
if (verifyCHK(pkx1) && Convert.ToBoolean(BitConverter.ToUInt16(pkx1, 8)))
{
// Save 1 has the box1 data
pkx = pkx1;
success = 1;
}
else if (verifyCHK(pkx2) && Convert.ToBoolean(BitConverter.ToUInt16(pkx2, 8)))
{
// Save 2 has the box1 data
pkx = pkx2;
success = 1;
}
else
{
// Sigh...
}
}
#endregion
}
}
if (success == 1)
{
byte[] diff1 = new byte[31*30*232];
byte[] diff2 = new byte[31*30*232];
for(uint i = 0; i < 31*30*232; ++i)
{
diff1[i] = (byte)(break1[offset[0] + i] ^ break1[offset[0] + i - 0x7F000]);
}
for(uint i = 0; i < 31*30*232; ++i)
{
diff2[i] = (byte)(break2[offset[0] + i] ^ break2[offset[0] + i - 0x7F000]);
}
if (diff1.SequenceEqual(diff2))
{
bool break3is1 = true;
for(uint i = (uint)offset[0]; i<offset[0] + 31*30*232; ++i)
{
if(!(break2[i] == break3[i]))
{
break3is1 = false;
break;
}
}
if (break3is1) save1Save = break3;
slotsKey = diff1;
}
else success = 0;
}
if (success == 1)
{
// Markup the save to know that boxes 1 & 2 are dumpable.
savkey[0x20] = 3; // 00000011 (boxes 1 & 2)
// Clear the keystream file...
for (int i = 0; i < 31; i++)
{
Array.Copy(zerobox, 0, savkey, 0x00100 + i * (232 * 30), 232 * 30);
Array.Copy(zerobox, 0, savkey, 0x40000 + i * (232 * 30), 232 * 30);
}
// Copy the key for the slot selector
Array.Copy(save1Save, 0x168, savkey, 0x80000, 4);
// Copy the key for the other save slot
Array.Copy(slotsKey, 0, savkey, 0x80004, 232*30*31);
示例9: fetchpkx
// File Dumping
// SAV
private byte[] fetchpkx(byte[] input, byte[] keystream, int pkxoffset, int key1off, int key2off, byte[] blank)
{
// Auto updates the keystream when it dumps important data!
ghost = true;
byte[] ekx = new Byte[232];
byte[] key1 = new Byte[232]; Array.Copy(keystream, key1off, key1, 0, 232);
byte[] key2 = new Byte[232]; Array.Copy(keystream, key2off, key2, 0, 232);
byte[] encrypteddata = new Byte[232]; Array.Copy(input, pkxoffset, encrypteddata, 0, 232);
byte[] zeros = new Byte[232];
byte[] ezeros = encryptArray(zeros); Array.Resize(ref ezeros, 0xE8);
if (zeros.SequenceEqual(key1) && zeros.SequenceEqual(key2))
return null;
else if (zeros.SequenceEqual(key1))
{
// Key2 is confirmed to dump the data.
ekx = xortwos(key2, encrypteddata);
ghost = false;
}
else if (zeros.SequenceEqual(key2))
{
// Haven't dumped from this slot yet.
if (key1.SequenceEqual(encrypteddata))
{
// Slot hasn't changed.
return null;
}
else
{
// Try and decrypt the data...
ekx = xortwos(key1, encrypteddata);
if (verifyCHK(decryptArray(ekx)))
{
// Data has been dumped!
// Fill keystream data with our log.
Array.Copy(encrypteddata, 0, keystream, key2off, 232);
}
else
{
// Try xoring with the empty data.
if (verifyCHK(decryptArray(xortwos(ekx, blank))))
{
ekx = xortwos(ekx, blank);
Array.Copy(xortwos(encrypteddata, blank), 0, keystream, key2off, 232);
}
else if (verifyCHK(decryptArray(xortwos(ekx, ezeros))))
{
ekx = xortwos(ekx, ezeros);
Array.Copy(xortwos(encrypteddata, ezeros), 0, keystream, key2off, 232);
}
else return null; // Not a failed decryption; we just haven't seen new data here yet.
}
}
}
else
{
// We've dumped data at least once.
if (key1.SequenceEqual(encrypteddata) || key1.SequenceEqual(xortwos(encrypteddata,blank)) || key1.SequenceEqual(xortwos(encrypteddata,ezeros)))
{
// Data is back to break state, but we can still dump with the other key.
ekx = xortwos(key2, encrypteddata);
if (!verifyCHK(decryptArray(ekx)))
{
if (verifyCHK(decryptArray(xortwos(ekx, blank))))
{
ekx = xortwos(ekx, blank);
Array.Copy(xortwos(key2, blank), 0, keystream, key2off, 232);
}
else if (verifyCHK(decryptArray(xortwos(ekx, ezeros))))
{
// Key1 decrypts our data after we remove encrypted zeros.
// Copy Key1 to Key2, then zero out Key1.
ekx = xortwos(ekx, ezeros);
Array.Copy(xortwos(key2, ezeros), 0, keystream, key2off, 232);
}
else return null; // Decryption Error
}
}
else if (key2.SequenceEqual(encrypteddata) || key2.SequenceEqual(xortwos(encrypteddata, blank)) || key2.SequenceEqual(xortwos(encrypteddata, ezeros)))
{
// Data is changed only once to a dumpable, but we can still dump with the other key.
ekx = xortwos(key1, encrypteddata);
if (!verifyCHK(decryptArray(ekx)))
{
if (verifyCHK(decryptArray(xortwos(ekx, blank))))
{
ekx = xortwos(ekx, blank);
Array.Copy(xortwos(key1, blank), 0, keystream, key1off, 232);
}
else if (verifyCHK(decryptArray(xortwos(ekx, ezeros))))
{
ekx = xortwos(ekx, ezeros);
Array.Copy(xortwos(key1, ezeros), 0, keystream, key1off, 232);
}
else return null; // Decryption Error
}
}
else
//.........这里部分代码省略.........