Help! I just logged into Stack Exchange, but I forgot what my password is! I need a way to work it out before I log off.
Luckily, I'm an excellent hacker. Not only was I able to find my password's hash, but I also found Stack Exchange's hashing algorithm! It takes the ASCII value of each digit multiplied by that digit's place, then sums all those values together. For example:
"135" -> 1*49 + 2*51 + 3*53 = 310
I remember that my password is 3 digits long, and that each character is a number between 0 and 5 inclusive (such that it will match the regex: ^[0-5]{3}$
), but that's still too many possibilities to guess. I need a program that can convert a hash back into potential passwords, but despite being an expert hacker, I can't code to save my life! I was able to write these tests out by hand though:
input -> output
288 -> 000 // lowest possible hash
290 -> 200, 010
298 -> 022, 050, 103, 131, 212, 240, 321, 402, 430, 511
318 -> 555 // highest possible hash
Can one of you write a program for me that will take in a hash and print all the possible passwords I could have used?
The input will always be able to produce at least one valid password. Any output format is allowed, as long as the strings can be clearly identified. I'm also not concerned about leading zeroes, so if a potential password is 001
, I'll also accept 01
or 1
.
Please help me from being locked out of Stack Exchange!
Scoring
This is code-golf, so the shortest answer in each language wins!
1
's Ascii value49
instead of48
? \$\endgroup\$"135" -> 1*49 + 2*51 + 3*53 = 310
\$\endgroup\$54
I can work out the zeroes in front. \$\endgroup\$