'How to generate Random Number-String(Alpha-Numeric) from String with given Key
So far i need to generate 6 length random key from given string I assume given string is always unique. With that i cant to plain so i need to encrypt into some 6 length random
String plainText = "please random me ";
String password = "secret Key";
String s = someMagicalFunction(plainText,password)
// s = "a23De1"
Solution 1:[1]
A six character alphanumeric string, using both uppercase and lowercase is in effect a 6 'digit' base 62 number (10+26+26=62). That gives an upper limit of 62^7-1, or about 2^43-1.
Use your input string and key to generate a number in the given range, truncating as needed, and convert it to base 62 before printing.
You do not say how secure you need the string generation to be. A non-cryptographic hash, such as the FNV hash, will be faster than a cryptographic hash like SHA256.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | rossum |