开发者

Algorithm to turn barcodes into game objects (monsters, items etc.)

I am about to write a game that turns barcodes into game items (like monsters, items, skills a.s.o.). Much like the old "Barcode Battler" game.

Unfortunately I am not very talented in mathematics. What I need is some hints how I could develop an algorithm to "parse" some stats out of barcodes (like Attack points, hit points, ...) without making it predictable.

So let's say I have this 8-digit barcode: 12345678

A friend of mine suggested to hash the barcode with MD5 and a salt but the problem I have with this is that I guess that will produce a lot of collisions. Also then it is difficult in a game designers view to predict chances to get some special attr开发者_开发问答ibutes.

So does anyone have an idea how I could start here?


An MD5 hash digest is 128 bits, so there are 2^128 possible hashes, or 340,282,366,920,938,463,463,374,607,431,768,211,456 (3.402823669e+38) possible hashes.

A barcodes has 12 decimal digits, but one of them is a checksum digit, so we can ignore it. There are 10^11 possible barcodes, or 100,000,000,000 (100 billion) possibilities.

According to this page: http://www.iusmentis.com/technology/encryption/pgp/pgpattackfaq/hash/#bruteforcemd5, you would need to try at least 2^64 hashes before you would end up with a collision on MD5, which means chances are incredibly small that you'll end up with a collision using just the set of barcodes.

The advantage to using MD5 over simply using the bits in the barcode is that for a given company the first part of the barcode will always be the same, and you'll have to account for that or you'll end up with a given company producing similar items.

The disadvantage is that the hashes will be spread all over the possible space of values, so you could end up with a large variety of items and huge gaps.

The only way to know is to experiment.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜