ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I see that the program is set to output all CAPS but there are many lower case characters in the output. It would be nice to have all options, output in all upper, lower or both. I thought I saw that somewhere when I was looking for the above uc/lc options.
Using this example as the average input string,
'W6ePreeSea24dSrp/a6ad?'
I would want the smallest to the largest permutations of the above string.
Anything A-F is a given as it's ascii code so no need to do anything but convert those digits to their ascii code. Only 0-9/a-z and G-Z need to be in the mix.
Mike
I see that the program is set to output all CAPS but there are many lower case characters in the output.
The program is set to make all conversions from a character to it’s hex value so that the value contains only upper-case hex digits. So ‘n’ will always be translated to ‘6E’ and never translated to ‘6e’. But there can be lower case letters in the overall output, since one of the criteria was that lowercase a-f would possibly map to themselves. Thus, ‘b’ will be translated to ‘b’ or ‘62’. That’s where the lowercase letters come in. Of course if you wanted that to be upper-case as well, just throw in a uc (or if you are quoting, \U will do).
Quote:
Originally Posted by mlewis
Using this example as the average input string,
'W6ePreeSea24dSrp/a6ad?'
I would want the smallest to the largest permutations of the above string.
Anything A-F is a given as it's ascii code so no need to do anything but convert those digits to their ascii code. Only 0-9/a-z and G-Z need to be in the mix.
I am not understanding your question here. Perhaps just show a small input string, and show the desired output, and explain how the desired output differs from what the snippet above outputs.
Also, I am wondering what the overall goal is here. If it is just mathematical curiosity, that’s fine, but if you are trying to solve a specific problem, perhaps there is a better way to do it.
>The program is set to make all conversions from a character to it’s hex >value so that the value contains only upper-case hex digits.
>So ‘n’ will always be translated to ‘6E’ and never translated to ‘6e’.
Basically, everything 0-9 can be either the digit or it's ascii code.
Everything A-F/a-f is permutated.
G-Z/g-z always converted to their hex code.
I'm sorry that I have such a hard time explaining this . I was talking with a programming friend last night, telling him about this and it took a little time to explain it even face to face. I'm basically just trying to figure out how to generate various outputs based on fairly specific yet changing inputs.
>Of course if you wanted that to be upper-case as well, just throw in a >uc (or if you are quoting, >\U will do).
The output needs to be fully either upper or lower case. So far, in testing this, only lower case works. If I try to use uc, there are always some lower case chars in the output.
>but if you are trying to solve a specific problem, perhaps there
>is a better way to do it.
I am trying to solve a problem and I am also hoping to end up with a small tool which I can learn a little from, by changing variables here and there, perhaps being able to use it for generating unique combinations of codes.
>The program is set to make all conversions from a character to it’s hex >value so that the value contains only upper-case hex digits.
>So ‘n’ will always be translated to ‘6E’ and never translated to ‘6e’.
Basically, everything 0-9 can be either the digit or it's ascii code.
Everything A-F/a-f is permutated.
G-Z/g-z always converted to their hex code.
permutated is not a word, and as I mentioned before what you want has nothing to do with permuting. Maybe you mean everything 0-9/A-F/a-f is either the digit or its ascii code?
If that's the case I think the map should be changed to this
Code:
map {
/[A-Fa-f0-9]/ && [uc $_, hexstr($_)] ||
# all other chars map to the hex rep. of their ASCII value
[hexstr($_)]
} split//, $input;
Quote:
The output needs to be fully either upper or lower case. So far, in testing this, only lower case works. If I try to use uc, there are always some lower case chars in the output.
putting a uc in the map entry seems to work
Quote:
I am trying to solve a problem and I am also hoping to end up with a small tool which I can learn a little from, by changing variables here and there, perhaps being able to use it for generating unique combinations of codes.
I've never used permutate or any variation of it in my life .
>as I mentioned before what you want has nothing to do with permuting.
Seems that different people call it different things because others have been saying just that, permutation. Doesn't matter what it's called, the real issue is my trying to explain what I need.
>Maybe you mean everything 0-9/A-F/a-f is either the digit or its ascii >code?
Yes, variations of the digit itself or it's ascii code value. At first I was using 0-9/A-F but you're right, 0-9/A-F/a-f would make more sense but the output would still remain all caps or all lower case.
>If that's the case I think the map should be changed to this
I'll give this a try, thanks very much for the input.
>putting a uc in the map entry seems to work
Strange. For me, it made all chars upper case but it left any c near the end of the result always lower case.
>Is the problem you are trying to solve a secret?
It's not a secret, I'm looking for a specific output based on an input.
I've never used permutate or any variation of it in my life .
>as I mentioned before what you want has nothing to do with permuting.
Seems that different people call it different things because others have been saying just that, permutation. Doesn't matter what it's called, the real issue is my trying to explain what I need.
I guess so, but I think at least some of the initial confusion over what you were asking for came from your use of the word permutation.
Quote:
Strange. For me, it made all chars upper case but it left any c near the end of the result always lower case.
Not sure how that would happen, with $input = "cc", I get
Code:
~/tmp$ ./comb.pl
CC
C63
63C
6363
I guess you can always use tr on the output without touching the code (input = "aA", without the uc in the map):
Code:
~/tmp$ ./comb.pl
aA
a41
61A
6141
~/tmp$ ./comb.pl | tr A-Z a-z
aa
a41
61a
6141
~/tmp$ ./comb.pl | tr a-z A-Z
AA
A41
61A
6141
Quote:
It's not a secret, I'm looking for a specific output based on an input.
I meant what is the problem that you want to solve using this tool that gives the specific output. Or do you just like looking at long strings of hex ??
>I meant what is the problem that you want to solve using this tool that >gives the specific output. Or do you just like looking at long strings of >hex?
This is something I'd like to understand, curiosity, and need to generate usable codes for an application.
The input would only be hex, using none of the following;
"*_+=:;@#~<>,.?/GHIJKLMNOPQRSTUVWXYZghijklmnopqrstuvwxyz
The challenge is having a known output string like I've posted and trying to figure out what the hex only input (either all lc or uc) string would be to get that output. Using A-Fa-f0-9 currently, I am still seeing a mix of uc and lc in the output.
So far, it seems pretty straight forward, it just takes the input and outputs all combinations in the same order.
So, what if I now added a hash key I think it's called. Let's say another hex number that the program uses to calculate the output. How does a hash key work if I'm using the right term. Basically, something that I could throw in which would further obfuscate the output.
Using A-Fa-f0-9 currently, I am still seeing a mix of uc and lc in the output.
Well maybe you miscopied something somewhere, why don't you post the result of cat comb.pl and ./comb.pl (replacing comp.pl with whatever you called the file).
Quote:
So far, it seems pretty straight forward, it just takes the input and outputs all combinations in the same order.
So, what if I now added a hash key I think it's called. Let's say another hex number that the program uses to calculate the output. How does a hash key work if I'm using the right term. Basically, something that I could throw in which would further obfuscate the output.
I hope that makes sense.
Mike
There are many different hash functions, but there's probably a Perl module for it somewhere. However if your final goal is to reverse a cryptographic hash function you should know that those are specifically designed to prevent that sort of thing, and a program that simply tries all combinations will take a long time (as in thousands or millions of years)
>However if your final goal is to reverse a cryptographic hash function >you should know that those are specifically designed to prevent that sort
Alright, it's time to explain this then. I've tried and tried not to get into specifics because I don't want anyone to think that this is about hacking or breaking codes for bad uses. But, making excuses gets you deeper and deeper into the toilet and then you do look like you're trying to do something bad . So, here's the story.
It starts with a piece of used hardware. I won't say which manufacturer it is because I don't want to potentially cause them problems by posting anything about their methods.
The hardware is no longer manufactured or supported so I can't get anything for it. In order for the machine to run, it needs a code entered at the console when it is installed. You are of course supposed to write that code down, which I had. I have two other's like it so I thought I had stored the code with those but it turns out I didn't and lost it.
Last week, after a good testing period to make sure all was good, I decided to simply default it rather than go into all of the settings and reconfigure, a lot easier to just default and start over. I'm sure you can guess the rest.
Now, I still have my code but, it's in the registry, already installed on the machine and it's in code such as I've posted. The code is entered as all lc or uc hex.
I also have a backup of the registry but the darn thing is in binary and I can't seem to find a way of converting that to an ascii file that I can simply re-import into the machine then could see my code again.
Actually, I can see it in ascii using Linux mc but I don't know how to convert it to ascii otherwise.
At some point, when I turn it off or have to reset something a little deeper which overwrites the registry, that will kill the machine and that will be a terrible thing for me. It took me a long time to find this used at a price I could afford.
So, the bottom lime is, I'm only trying to figure out the hex input string so that I can re-enter it at some point. That's the honest to goodness truth of the matter.
And, I've also now become interested in this tool we're creating as something I might be able to use for my own code generating uses down the road once I better understand how reliable these types of things can be.
By the way, I get Out of Memory errors with longer strings.
Actually, I can see it in ascii using Linux mc but I don't know how to convert it to ascii otherwise.
If you can see it in ascii, can't you just write it down on a piece of paper? This doesn't sound like it's obfuscated/encrypted at all. Does mc mean Midnight Commander?
>If you can see it in ascii, can't you just write it down on a piece of >paper? This doesn't sound like it's obfuscated/encrypted at all.
Oh my god, what a nightmare but I finally got it all back and working along with a backup of my code. Actually, many copies.
I won't get into it all but I finally got the backup registry working after a lot of messing around.
>Does mc mean Midnight Commander?[/QUOTE]
Yes, it's one of my favorite tools .
So, I'm still interested in this little program if anyone else is. I'd like to understand how hash codes work by including one in this little piece of code. Wish a hash code, then as tiny as it is, it would still make a great code generator would it not?
I know I can download a thousand of them but this is cooler as it's sort of community made.
If you can see it in ascii, can't you just write it down on a piece of paper? This doesn't sound like it's obfuscated/encrypted at all. Does mc mean Midnight Commander?
Sorry, I forgot to explain this but yes the file can be viewed using mc but I can't manipulate it in any other way. I found that I was able to see the file using windows commander which is how I finally managed to convert it to text.
It looks like a binary file to everything but mc on both linux and win.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.