I built a small program tonight to better my understanding of how strings concatenate from multiple sources. I decided a simple password generator was the way to approach this. Everything I have done before has been in Python 2.x. I have decided as of today I am making the leap into Python 3.x.
I have included my code below. Hopefully I have cleaned it up enough. When trying to learn concepts I tend to write a lot of tests in-line, run, then clean up. This isn't the best way.
I first start by creating my available characters in strings. I realize you could just put this all in one string, or array, but this was not the point of what I wanted to learn.
I then built the only user interaction, which asks how long of a password you need.
After this we build our primary random string. We first add a random number (somewhere between 10 and 1000) of lower case letters, then capital letters, followed by available symbols, and finally numbers.
This should give us a string of between 40 and 4000. From there we can use our PRNG included within python to pull a number of random values from this string by the index number within the string. Then we iterate and return the number of values needed for our password.
*Note* This is not a secure password vault/generator/etc *note*
This password is then printed for your viewing pleasure, it is also placed into your computer's clipboard so you can use it where needed.
It was a fun quick project which allowed me to learn some fun concepts. For example if I were to use
randStr = randStr.join([number[randomIndex((number.__len__() -1))] for i in range(randomGenerator())])
instead of
randStr = randStr + ''.join([number[randomIndex((number.__len__() -1))] for i in range(randomGenerator())])
Then it produced more numbers than wanted (exponentially more). This caused even this simple program to take up 100mb of ram. I also would not get a good sample of all 4 categories for the password as a result. It was often building passwords with 1 cap in it and the rest lower case.
The other big win for me from this project was the join statements themselves. I found another blog explaining how to properly concatenate strings in python. Initially I dove into this with no research and just started writing code (this seems to help me wind down as well). Though lack of planning beforehand does not always make for even decent code...
Initially I was doing the below to build and join my random string
def addStr(randomLen):
value = ''
for num in range(randomLen):
value += randomLet[randomIndex]
return value
But this post:
https://waymoot.org/home/python_string/
showed me how to improve my efficiency greatly
def addStr(randomLen):
return ''.join([randomLet[randomIndex] for i in range(randomLen)])
This allowed me to go from about 3k concatenations per second, clear up to 119k. While this honestly doesn't matter for this program, it is something to tuck away for later.
Next, after all my experience with BSAFE I think, I will look at how to write secure numbers in Python (build a PRNG that will pull data from random or urandom. But also that will keep it secured and clear everything as it completes.
Would be interesting to see what libs are out there to do so and a ton of fun to try and write a few things with the standard libs only. I have always enjoyed Python, but the more I use it, the more I love Python so much more than Java or C/C++.
Enjoy!
Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts
Friday, January 8, 2016
Code again
It has been a while since I have updated this. I received the last of the parts for my CoreXY/H-bot designed 3d printer. I should be putting that together over the next 2 weeks. I'll document this as best as I can.
Tonight I came home tired, so I decided to write a small python program just to exercise and to help me learn Python 3.x. I will put up another post specifically about this.
Tonight I came home tired, so I decided to write a small python program just to exercise and to help me learn Python 3.x. I will put up another post specifically about this.
Monday, December 28, 2015
One of my favorite python books has a Udemy course attached to it. Until the end of the year it is free!!! Please go sign up and you can go over the course as you have time, (you do not need to complete the course before the end of the year.
https://www.udemy.com/automate/?couponCode=RESOLVE_TO_CODE_2016
The book is released under creative commons
https://automatetheboringstuff.com/
Please pick this up if you have any interest in coding at all. Python is one of the best languages to learn a programming foundation, and you will continue using it through your whole career as well.
https://www.udemy.com/automate/?couponCode=RESOLVE_TO_CODE_2016
The book is released under creative commons
https://automatetheboringstuff.com/
Please pick this up if you have any interest in coding at all. Python is one of the best languages to learn a programming foundation, and you will continue using it through your whole career as well.
Thursday, August 13, 2015
Keyloggers, password hash cracking, and more python fun
Worked through the keylogger over the past few days. Been having fun seeing what I can get it to pull. I want to see if I can pull location of mouse pointer too, that is next step.
Built a small python program that will crack password hashes, it is rather simple at the moment, but holds promise. I'll release source on these when they are working at least most of the way.
Python is a fun language and I use it for most simple things I do around my systems. Need to take a closer look at 3 as everything I do is in 2.7 still. I use python for organization and cleaning my HDDs. I am a habitual data hoarder. I have random text files of notes I wrote over 10 years ago... I think it's time to clean.
I use one script that looks at files last access date and generates a report for me. That way I can go look at them and see if I still want to keep them. I ignore system and program files. This is almost exclusively pointed at my data server. It also will read from a blacklist and will ignore files there (picture folders). I have it currently set at 6 months but probably should drop that down.
Built a small python program that will crack password hashes, it is rather simple at the moment, but holds promise. I'll release source on these when they are working at least most of the way.
Python is a fun language and I use it for most simple things I do around my systems. Need to take a closer look at 3 as everything I do is in 2.7 still. I use python for organization and cleaning my HDDs. I am a habitual data hoarder. I have random text files of notes I wrote over 10 years ago... I think it's time to clean.
I use one script that looks at files last access date and generates a report for me. That way I can go look at them and see if I still want to keep them. I ignore system and program files. This is almost exclusively pointed at my data server. It also will read from a blacklist and will ignore files there (picture folders). I have it currently set at 6 months but probably should drop that down.
Subscribe to:
Posts (Atom)