# Can you find the villain's password? [closed]

### Background

You work for the police force as a programmer.

A villain has planted a bomb in the city, luckily the police force has captured both him and the bomb. The bomb is really complicated to disarm, however it has a password input to disarm it.

The villain, being cocky, has told you that there was no way you'd find the password as you'd take X time to brute force it. You notice that the keyboard can only input english letters (lower and upper case) and digits.

Assuming you can try Y passwords per second, and that the brute force character order would be a-z A-Z 0-9, you are to create either a full program or a function that takes as input both X (in seconds) and Y (passwords/second) and outputs the villain's password.

X can be a float but Y will always be an integer.
(X*Y should always be an integer)

Your code has to solve the problem using math instead of relying on trying several options or creating huge arrays and simply indexing them with X*Y.

### Example in JS

var c="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var b=62;
function num(x){
var n=0;
while(x>=0){
x-=Math.pow(b,++n);
}
return n;
}
function reduce(x, n){
while(--n>0){
x-=Math.pow(b,n);
}
return x;
}
function pass(x, y){
x=x*y;
x--;
var p=[];
var n=num(x);
x = reduce(x, n);
do{
var t=x%b;
x=(x-t)/b;
p.unshift(t);
}while(x>0);
return ("a".repeat(n)+p.map(f=>c[f]).join).substr(-n);
}


Assuming my code is correct here are some example outputs.
(If there are any errors please tell me so that I can correct them)

pass(0.000, 1000); // "" or anything that won't be mistaken for a password
pass(0.001, 1000); // "a"
pass(0.002, 1000); // "b"
pass(0.027, 1000); // "A"

//A password that would take a year to brute force at 1000 passwords/second
pass(3600*24*365, 1000) // "HzmZmr"


My code is awful and ungolfed but it's only to serve as an example. Since this is code-golf shortest answer in bytes wins.

## closed as unclear what you're asking by NonlinearFruit, Rɪᴋᴇʀ, Sriotchilism O'Zaic, Peter Taylor, NoOneIsHereFeb 1 '17 at 17:19

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• "You cannot brute force" I'm not quite sure what that implies... does it mean we can't simply generate the next Y passwords each second and then output after X seconds? – ETHproductions Feb 1 '17 at 13:51
• Oh I think I get it... we know that X is the upper bound on time so we take the Y passwords/second and generate Z passwords where Z = XY? Then the Z'th password would be correct? If this is the case, what's the minimum length password that the bomb accepts? – Poke Feb 1 '17 at 14:20
• @Poke I think we are supposed to output the (X*Y)th string from a, b, c,..., y, z, A, B,...,Y, Z, 0, 1, ..., 8, 9, aa, ab, ac, ad,.... I'm voting to close as unclear until that gets cleared up though. – Riley Feb 1 '17 at 14:24
• Before posting your challenges, you could post on Sandbox first, there you can receive some feedback to improve your challenge. – Rod Feb 1 '17 at 17:09
• This still needs an actual specification (making us reverse engineer it from a reference implementation doesn't count), but judging by the answers it would likely be close enough to codegolf.stackexchange.com/q/54105/194 to be closed as a dupe anyway. – Peter Taylor Feb 2 '17 at 6:56

# Jelly, 9 bytes

×ḃ62ịØWŒs


Try it online!

### How?

×ḃ62ịØWŒs - Main link: X, Y
×         - multiply X by Y
ḃ62      - convert to bijective base 62 (uses modulo arithmetic under the hood)
ị     - index into (1-based)
ØW   - word yield -> "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"
Œs - swap case


# Python 2, 121 bytes

x,y=input()
r=range;b=map(chr,r(97,123)+r(65,91)+r(48,58))
i=int(x*y)
p=b[i%62]
while i/62>0:i=i/62-1;p=b[i%62]+p
print p


Try it online!

This basically calculate the x*y in base 62
For a recursive solution at 125 bytes

x,y=input()
r=range;b=map(chr,r(97,123)+r(65,91)+r(48,58))
f=lambda i:(f(i/62)if~-i/62>0else'')+b[i%62-1]
print f(int(x*y)+1)