我想生成超过10000个随机密钥K(32个字节)并需要将它们用于RC4并且需要计算第二个RC4密钥字节为0x00的事件的频率。
我编码了这个解决方案,我是对的吗?
namespace Project.Converters
{
class Item_to_FullItem : DependencyObject, IValueConverter
{
public Vehicle VehicleItem
{
get { return (Vehicle)GetValue(dependencyProperty); }
set { SetValue(dependencyProperty, value); }
}
public static readonly DependencyProperty dependencyProperty =
DependencyProperty.Register(nameof(VehicleItem), typeof(Vehicle), typeof(Item_to_FullItem), new PropertyMetadata(null));
public object Convert(object value, Type targetType, object parameter, string language)
{
if (VehicleItem != null)
{
if (value != null)
{
string _formatedValue = string.Empty;
switch (VehicleItem.Category)
{
case 1:
return "#" + value.ToString();
case 2:
case 3:
return value.ToString() + "º";
default:
return value.ToString();
}
}
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}
答案 0 :(得分:0)
您的问题没有多大意义,但以下代码生成10,000个随机32字节密钥,然后计算生成密钥的次数,其中第二个字节为零:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int run_test() {
int c = 0;
for (int i = 0; i < 10000; i++) {
char buf[32];
for (int j = 0; j < 32; j++) {
buf[j] = rand();
}
if (buf[1] == 0x00) { c++; }
}
return c;
}
int main(int argc, char* argv[]) {
srand(time(NULL));
printf("%d", run_test());
}
免责声明:此处未使用CSPRNG,请勿以这种方式实际生成密钥。