Suppose your bank clerk gives you an arbitrary password such as hel34/hjal0@#
and you cannot remember it without writing it to a paper. Dilemma: you never write passwords to paper. So you try to invent an encryption, one-to-one map, where you write only a key to a paper, only numbers, and leave the rest junk to your server. Of course, the password can consist of arbitrary things.
mvds has the correct idea, to change the base. Eugene noticed an error, so the one-to-one-map should be like:
prime1*prime2*...*primeN <-开发者_JAVA百科---- encoding -------> String
I don't know if I really understand your problem, but you could see your input as a base-62 number (26+26+10), which you could read in as an integer, and then process it any way you like. Then convert the result back to your custom base-62 format.
So as an example, your digit range is [0-9a-zA-Z]
so 0
= 0 decimal and Z
= 61 decimal, and 10
would be 62 decimal.
Then 9aZ
would be 9*62*62 + 10*62 + 61 = 35277 decimal, which has prime factors 3 * 11 * 1069.
Converting them back would lead to: 9aZ = 3 * b * hg
First of all, your numeric code can't be shorter, than the password: shorter password reduces protection strength. So you need to keep the password either intact (and just encode it) or make it even longer.
When talking about encoding, you can use BASE10 or BASE16 encoding. With Base16 encoding you have 2 characters per original character (if we stay within ASCII charset), with Base10 encoding the length would vary, and to ensure correct decoding you would end up using 3 characters per original ASCII character.
精彩评论