Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have a method that pseudo-randomly encrypts a byte array. I would like to convert the encrypted byte-array to a C# int (4 bytes), while observing a user-specified lower and upper bound (e.g. give me a number between 1 and 10)
What is the most secure and performant way of achieving this?
You could use System.ByteConverter.ToInt32(arr, start_index).
From your description of the array, the start index would likely be zero.
I am not sure what you mean by upper and lower bound, but if you mean you want a random number, you could use a variety of functions to get a value in between the two numbers. If you have semi-uniform distribution, the modulus function would work nicely. In that case, your random number would simply be lowerBound + (System.ByteConverter.ToInt32(arr, start_index) % (upperBound - lowerBound)).
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to generate number as format above and I try to use UUID() and GUID() but it is not what I want(difference format and it is hexadecimal not number)
anyone have any idea or logic to do it?
The simplest way to generate 1000000000000 unique numbers is just an ever-increasing sequence:
long i = 42; // whatever
string key = $"{i / 100000000:0000}-{(i / 10000) % 10000:0000}-{i % 10000:0000}";
The next time, increase i before generating the key.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have an input byte array which is huge in size ( > 8000 bytes). I need to store this byte array in DB, and fetch later for further operation.
The problem is, this byte array column is unique. Assume that if I need to retrieve the entire table information on this byte array column. It becomes extremely costly operation when it comes to byte comparison. So thought of storing the Hash Value of this byte array just to make the comparison operation easier.
Just wanted to know if hash value which is generated from the byte array will be unique OR is there any other way to achieve this.
If the size (in bytes) of the hash is smaller than 8000, this is not possible. After all, there are 256 ^ 8000 possible inputs, so there must be at least that many possible outputs if the hash function needs to be unique.
As the default C# hashcode returns an int, which (depending on your architecture) is 32 or 64 bits (so 4 or 8 bytes), this is not even close to be possible with the default hash function. (Of course, you could write your own hash function, but that's quite pointless.)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I don't know C# but I have to do a update to a function that send a key to be encrypted.
I need to send a key with 64 characters, but the function that I have here only accepts 32 characters.
The function that initialize this process is:
Byte[] kkey = System.Text.Encoding.UTF8.GetBytes(sEncKey);
What I have to do for this accept a 64 characteres key?
The code you have included creates an array of type Byte which includes a number of elements matching whatever number of characters you provide in sEncKey.
It is my understanding that you are passing kkey to some function that will perform the encryption, and that this function only accepts a byte array of size 32. If this is correct, then you can't automatically increase the key size to 64 just by sending a longer key - it is the function you will have to change first, not it`s input.
Sound's like you're trying to increase security by using a larger key without replacing the lock first. Get a bigger lock first, then you can use a bigger key.
Also, if you need more help or guidance with this, you will need to provide info about the function, as well as some relevant code.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a situation on my C programming here and just wondering whether my solution is the correct way:
I have a LED display with particle count sensor and will show 6 digit of seven segment numbers as the count value. The sensor will give voltage input value. The input is from 0V to 10V. So the range of 0V-10V need to be shown in the display as 000000 to 999999 count.
My solution is:
Display number = Input voltage * 99999.9
For example:
Display number = 10.000*99999.9=999999
Display number = 5.500*99999.9=549999
Display number = 2.300*99999.9=229999
Is this the correct solution? I notice that I will get a lot of 9 on the display value.
The most usable and user friendly solution is to ignore the fact that your most significant digit is capable of displaying up to 9 and simply multiply by 10000 unless you desperately need the maxim resolution in which case simply use a scale factor of 100000 and document that your range is 0-9.99999.
My reasoning is that it is better to either loose one digit in the accuracy across the whole range or clip just the maximum value than to have an error across the entire range.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is there a way to reduce the number of figures of a number?
Example:
double d = 222222222222222224444444444444.0
I want to "serialize" it like 17[2]13[4] for example.
The idea is to reduce the number of "chars" used by the number.
double d = 222222222222222224444444444444.0
You can't have a double that big in the first place.
I want to "serialize" it like 17[2]13[4] for example.
The idea is to reduce the number of "chars" used by the number.
A double only takes 8 bytes regardless of its value. There doesn't seem to be any actual point to this.