#🔒 String permutations
73 messages · Page 1 of 1 (latest)
@cyan shell
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
my_str = "james.robert"
for i in range(len(my_str)):
if my_str[i] != ".":
print(my_str[:i] + chr(ord(my_str[i])-32) + my_str[i+1:])
``` I tried doing for a single iteration, but rn I cannot think of how to make all the possible combinations
I would skip ord and do something more like my_str.upper()[i] or my_str.lower()[i] to get the different cases
You could leverage itertools.product here
You actually want the permutations or do you just want to calculate how many there are?
yeah I can also do .capitalize, that's not where I am having troubles tho
I want to print all possible strings
i'd use itertools.product too; count the letters that can be capital and generate lists of true/false for capitals
I see, I thought of that but I am not sure if I know how to use it properly
all letters can be capitalized except the point
yes, you'd of course not count that because it can't be capital
turn each character into a list of both possible capitalizations (or the only possible capitalization, for characters like .). feed all these lists to product.
note that there'll be like 2048 capitalizations.
yeah, thats what I hoping for, the more the better
Is it possible to get the code? I am not trying to achieve a big project with this.
whatever you do, i reckon to account for the dot not changing you'd need to generate this new string without special characters and then construct the proper version
can I ask why you're trying to achieve this?
yeah, the dot is not a big deal, I could insert it after every 6 characters in each reconstructed string
Well it might get misinterpreted
meaning?
You are familiar with CTF challenges right?
CTF means capture the flag
just making sure you weren't coming up with some sort of roundabout solution for something
Ahh yeah I'm familiar with CTF, but not sure how it relates to programming here
Are you brute forcing a password?
oh well there is a challenge where I have an admin panel and I need to bypass it in order to gain access
more or less yeah
this is the challenge - as proof
and I need to guess a 1-4 digits pin in order to gain control, but after 3 attempts the user accounts get locked out, but the server thinks that james.robert is different than james.Robert but at the same time consideres it a valid username, which exists in their database
If this is an open/active competition, then asking for help here might constitute an unfair advantage.
Now I see why you said the more the better
Yep
I was just noticed the "terminate in an hour" thing
so is there a chance that you could guide me more forwardly to get that script? I did not user itertools.product much
Yes, take a look at what @rugged tundra said
And we can help guide you from there
Yeah, its been up for a couple of days, more guys try to do it and I kinda found the solution but donno how to automate it
alright, I have to go and eat right now but I will try to be quick
Wouldn't this alter the format of the initial string? Like wouldn't I get Jjames? Or unordered usernames?
Like asmej
product's outputs take exactly one item from each iterable and don't reorder them.
I see, I will try as soon as I finish eating, thanks
I tried with a comma too, I am not sure I understand how the params are utilised by the function
cuz I get an output like this and it changed its order
that'd be because you're doing repeat=12
yeah cuz the total length of the string was 12, I shortened the string and the repeat
you're calculating all 12-length strings consisting of 24 possible characters at each position
that's not what you want - you want to, for each position, provide a list of up-to-2 possible characters.
so make a list consisting of a list for each character (e.g. for the first character, "j", the corresponding list would be ["j", "J"], ["."] for the dot), and unpack it into product.
oh, it takes a list of lists?
no, but it does take any number of iterables
!e
import itertools
x = ["aA", "bB"]
print(list(itertools.product(*x))) # equivalent to itertools.product(x[0], x[1])
@rugged tundra :white_check_mark: Your 3.12 eval job has completed with return code 0.
[('a', 'b'), ('a', 'B'), ('A', 'b'), ('A', 'B')]
would a list comp work here?
my_list = [[a,b] for a,b in zip(list(my_str), list(my_str.capitalize())]
to get my list of lists?
so its a list of strings, not a list of lists
I used the former because it's simpler to type, but it doesn't matter for product - just needs to be iterable
sure, that looks valid
i'd have written it as [[x.lower(), x.upper()] for x in my_str]
yeah it gave me an error but I fixed it
I managed to reach my goal, thank you
oh makes sense, thank you
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.