0

I'm trying to create unique numerical ids based on another unique numerical usernames (to obfuscate) via powershell. For example, username 123423 will be a 5621723. Preferable less than 20 digits

Looked into if CRC16 hash would works, but it's a possibility it will collide. hashids.org looks promising, also https://github.com/archer884/crockford.

any suggestions how you could achieve this, preferable in powershell?

Thanks

SuperDOS
  • 301
  • 1
  • 3
  • 16
  • there is reason GUIDs are so long ... [*grin*] i don't think you will be able to generate a UID that is so short and have an acceptable unverified non-repeat rate. have you thot about just making the id, testing it for uniqueness, and then repeating as needed until you get a unique number? ///// i would simply go with an incrementing number ... – Lee_Dailey Sep 30 '19 at 13:27
  • Will you store this mapping (unique alpha username to unique numeric) in a database? What's the range of values of username? That is, is username limited to ASCII letters? ASCII letters and numbers? UTF-16 letters and numbers? Does the result need to appear random (as opposed to appearing sequential)? – Mike Sherrill 'Cat Recall' Sep 30 '19 at 13:33
  • This will be in a database so the "encrypting" could be done directly in the MSSQL. Sorry wrong of me, the Usernames will be numerical only but I want to obfuscate them with another unique numerical value since they are semi-sensitive. updated the question. – SuperDOS Sep 30 '19 at 13:41
  • @Anthon : Is there a compelling reason to *calculate* the new id number instead of selecting a random integer in the range of a signed or unsigned big integer, and retrying whenever there's a collision? – Mike Sherrill 'Cat Recall' Sep 30 '19 at 13:53
  • I need to be able to reverse the new id number so I can match them against another database. a little background, I have a database with users but the same can user can exist several times. each row in the database table has a unique ID. but I can't use that since I need a unqiue ID tied to the user, so my idea was to take the SSN (which I also have) and use it as unique for the user even if they appear many times in the db. But I want to obfuscate it when copying the rows to another database. sorry might be a bit fuzzy, maybe need to think this trough a bit :) – SuperDOS Sep 30 '19 at 14:09
  • 1
    Have you considered playing with the bits? You could convert the number from decimal to octal or base-11 or something. You could rotate the bits. You could ROT5 the digits and reverse the string. That sort of stuff – Patrick87 Sep 30 '19 at 14:14
  • Looked into converting to other bases and mirroring the string. think it's good enough for this. :) – SuperDOS Sep 30 '19 at 17:58
  • I don't know if you can convert the code to Powershell, but this looks like a perfect use of multiplicative inverse. See https://stackoverflow.com/a/21975324/56778, and the linked blog entries. Also see https://stackoverflow.com/a/34420445/56778 for a simple example in C#. – Jim Mischel Sep 30 '19 at 18:54
  • By the way, if you're using the SSN, *do not* let the obfuscated number escape to the Internet. Obfuscation is not encryption. It's not secure. Obfuscation is discoverable. People *will* try to reverse-engineer your keys, and if they succeed, they then have the ability to capture users' SSNs. Also, you're going to have some trouble if you have international customers or anybody else who doesn't have a valid SSN. – Jim Mischel Sep 30 '19 at 18:59

0 Answers0