Hashing a 48-bit key into a 16-bit value
Ask the manufacturer about any patterns in the generation of this number. It's quite likely that some of these 24 bits identify the production batch or the part of the world to ship to, making they the prime candidates for being trimmed out.
Make it clear in the request that you are aware and accept that they can change numbering policy anytime without notice. This should make them more likely to give the information.
How to shorten a 64-bit hash value down to a 48-bit value?
If the 64-bit hash is good, then selecting any 48 bits will also be a good hash. @Lee Daniel. Of course, information is lost and not reversible.
unsigned long long Mask48 = 0xFFFFFFFFFFFFu;
unsigned long long hash48 = hash64 & Mask48;
If 64-bit hash function is weak, then mod by the largest prime just under pow(2,48)
. Some buckets will be lost. This will not harm a good hash, yet certainly make weak hashes better.
unsigned long long LargestPrime48 = 281474976710597u; // FFFFFFFFFFC5
unsigned long long hash48 = hash64 % LargestPrime48;
Is there a perfect hash function for the combined input sets of IMEI numbers and MAC addresses? (C implementation)
There's no way to make a perfect hash over an unknown, growing input set. You could simply make the field one bit larger than whichever of IMEI or MAC is larger, and use that bit to flag which type of identifier it is, along with the entire IMEI/MAC. Anything smaller will have collisions, but they're probably quite rare.
how to hash user input into unique id
You can choose whatever hashing algorithm you like and trim it to the length you need.
E.g.: last 6 digits of the MD5.
Good hash algorithm for list of (memory) addresses
You might consider some sort of CRC.
Perhaps a CRC64.
Generating a 'unique' 3 character tag from 4 Hex digits
I worked through the responses above and came up with a solution. It's not perfect, but it works...
if [ ! -f /home/pi/MAC_ADDRESS ]; then
BASE28="ABC3DEFG4HJK6LMN7PQRT8UVW9XY";
arg1=$(ifconfig | grep eth0 | awk '{if ($4 == "HWaddr") print $5 }');
echo $arg1 > /home/pi/MAC_ADDRESS;
arg1="${arg1//:}";
arg1=${arg1:8:4};
arg1=$(echo $arg1 | tr '[:lower:]' '[:upper:]');
arg1=$(bc <<< "obase=28; ibase=16; $arg1");
c="";
for i in $arg1; do
if [ $i -eq 08 ]; then
i=8;
fi
if [ $i -eq 09 ]; then
i=9;
fi
b=${BASE28:$i:1};
c=$c$b;
done
c=${c:(-3)};
echo $c > /home/pi/CLIENT_ID;
fi
In the for loop I needed to fix the 08 and 09 for some reason...
Are there common methods for hashing an input file to a fixed set of values?
Okay, that's a very nice question. I would say: don't use hash, because this won't be a nice way for the player to predict patterns. From cognitive theory we know that one thing that is interesting in games is that player can learn by trial and error. So if player gives the input of an image of a red dragon and another image of a red dragon with slightly different pixels, he would like to have the same monster appearing, right? If you use hashes that would not be the case.
Instead, I would recommend doing much simpler things. Imagine that your raw piece of input is just a byte[]
, it is itself already a list of numbers. Unfortunately it's only a list of numbers from 0 to 255, so if you for example do an average, you can get 1 number from 0 to 255 . That you could map to a number of monsters already, if you need more, you can read pairs of bytes and just compose Int16
, that way you will be able to go up to 65536 possible monsters :)
Related Topics
How Does Sort Work Out How Much Ram There Is
Linux Set End of File (Shrink, Truncate, Cut Out Some Data @ End)
How to Add Multilanguage Support to a Yocto Build
How to Extract Text Which Matches Particular Fields in Text File Using Linux Commands
In Bash Tee Is Making Function Variables Local, How to Escape This
How to Generate Files in a Docker Container for Having The Same Owner as The Host's User
Using Find But Only in Subdirectories Matching Certain Pattern
How to Pipe The Output of an Ls on Remote Server to The Local Filesystem via Sftp
Assign Output of a Shell Command to a Variable
Quickest Way to Select/Copy Lines Containing String from Huge Txt.Gz File
Symbol Lookup Error Undefined Symbol, But All Symbols Seem to Be Present
Sysfs Interface. I Can't Export Gpio Pins in a Xilinx's Board (Zybo and Other)
Copy File to Backup Directory Preserving Folder Structure
Kaggle API Issue "Could Not Find Kaggle.JSON. Make Sure It's Located In......"
How to Upgrade a Package in Linux That Was Built from Source