Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; even without the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # you should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- #
- # All code posted on my Pastebin is designed for Linux (Debian-based)
- #
- # Description:
- # This file takes a text file that is setup like the following...
- # "string1", "string2", "string3"
- # or
- # string1, string2, string3
- # or
- # string1 string2 string3
- #
- # It then formats it to the following and replaces the original content...
- # string1
- # string2
- # string3
- #
- # Perfect for making a dictionary file for password cracking *wink wink*
- # The different words have to be separated by a space to make the new line
- import argparse
- from subprocess import call
- def main(filename):
- with open(filename, "r") as inFile:
- with open("/tmp/outFile.txt", "w") as outFile:
- print("\n[*] This will erase the contents inside '%s' and will be replaced with the formatted version.\
- \n[*] If you still want the contents, copy them into a new file and pass that file into here.\
- \n[*] Do you wish to continue? [Y/n]" % filename),
- ans = raw_input("")
- if ans.lower() == 'y':
- pass
- else:
- return 1
- contents = inFile.read()
- formatted_contents = formatString(contents)
- outFile.write(formatted_contents)
- command = "rm %s && cp /tmp/outFile.txt %s && rm /tmp/outFile.txt" % (filename, filename)
- call(command,shell=True)
- print "[*] File: '%s' was successfully formatted into a dictionary file!\n" % filename
- def formatString(string):
- bad_chars = ["\"",","] # add/remove bad characters in here if needed
- listed_string = list(string)
- for x in range(0, len(listed_string)):
- if listed_string[x] == " ":
- listed_string[x] = "\n"
- elif listed_string[x] in bad_chars:
- listed_string[x] = ""
- elif listed_string[x] == "\n":
- pass
- return "".join(listed_string)
- parser = argparse.ArgumentParser()
- parser.add_argument("fileToFormat",help="The file you want to format",type=str)
- argv = parser.parse_args()
- main(argv.fileToFormat)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement