Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Map;
- import java.util.Set;
- import java.util.concurrent.TimeUnit;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.util.stream.Collectors;
- /**
- * @Author: Xyle | integerarray@hotmail.com
- */
- /* "FileParser" yeah... let's call it that LOL */
- public class FileParser {
- /* Fastest execution for parsing and writing 125.6k files was 45.0 seconds! Total written bytes: 10,734 KB.
- // Eventually, write code that shows frequency of passwords in order.
- // static HashMap<String,Integer> passwords = new HashMap<String,Integer>();
- /**
- * The encryption algorithm used in RecklessPK is Base64.
- * Project insanity uses character serialization. Read PasswordUtils.java for information on deserializing.
- */
- static String ENCODING = "UTF-8";
- static boolean DESERIALIZE = false;
- static String CHARACTERS_PATH = "C:/Users/Gacoa/Desktop/characters/"; // Must have '/' at the end before last quote.
- /* Format: static String PASSWORD_LINE = "character-password ="; // Space after '=' causes StringOutOfBoundsException */
- static String HASH_LINE = "Pass="; // More of a "hash" than a password. Use "character-password =" for 'Project Insanity' char files.
- static String SALT_LINE = "Salt=";
- static String IP_LINE = "IP=";
- static File FOLDER = new File(CHARACTERS_PATH);
- static String EXT = ".txt"; // Sometimes character data may be stored in ".dat" extension.
- static File OUTPUT_FILE = new File("recklesspk_july_25_2015.txt");
- public static void main(String[] args) {
- long startTime = System.nanoTime(); // Set current time in nanoseconds to a memory address to be calculated at end of program.
- String username = "";
- //String password = ""; // Use this variable when not dealing with encrypted passwords
- // ( excluding serialized passwords, use: deserialize method in PasswordUtils.java ).
- File[] listOfFiles = FOLDER.listFiles(); // Gets the total amount of files in a directory. @CHARACTERS_PATH
- for(int i = 0; i < listOfFiles.length; i++) { // i being the index of the current File.
- if(listOfFiles[i].isFile()) {
- username = listOfFiles[i].getName().split("\\.")[0]; // The username is the name of the file with ".txt" extension truncated.
- try {
- String hashLine = Files.readAllLines(Paths.get(CHARACTERS_PATH + username + EXT)).get(1); // Second line of current File
- String saltLine = Files.readAllLines(Paths.get(CHARACTERS_PATH + username + EXT)).get(2); // Third line of current File.
- String ipLine = Files.readAllLines(Paths.get(CHARACTERS_PATH + username + EXT)).get(3); // Fourth line of current File.
- // Substring the password at the end of "Pass=" until the end of the line.
- String indexHash = hashLine.substring(HASH_LINE.length(), hashLine.length());
- String indexSalt = saltLine.substring(SALT_LINE.length(), saltLine.length());
- String indexIp = ipLine.substring(IP_LINE.length(), ipLine.length());
- /* A bad way of checking if the File name contains more than one space and if the File contains numbers. */
- // if(!username.contains(" ") && !username.contains("0") && !username.contains("1") && !username.contains("2") && !username.contains("3") && !username.contains("4") && !username.contains("5") && !username.contains("6") && !username.contains("7") && !username.contains("8") && !username.contains("9")) {
- /* Formatting the output to be written to the output File. */
- String output = username + ":" + indexHash + ":" + indexSalt + ":" + indexIp;
- try(PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(OUTPUT_FILE, true)))) {
- //<bulk>
- /* Writing to file */
- out.println(output);
- /* Console */
- System.out.println(output);
- }catch (IOException e) {
- e.printStackTrace();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- //finish
- long endTime = System.nanoTime();
- long duration = (endTime - startTime);
- double totalFiles = listOfFiles.length;
- DecimalFormat formatter = new DecimalFormat("#,###");
- String files = formatter.format(totalFiles);
- String kilobytes = formatter.format(1 + (OUTPUT_FILE.length() / 1024));
- double time = ((double) Math.round(duration / 1000000000.0) * 100.0) / 100.0;
- System.out.println();
- System.out.println("Finished writing " + kilobytes + " kilobytes to " + "./" + OUTPUT_FILE);
- System.out.println("Files parsed: " + files);
- System.out.println("Time: " + time + " seconds");
- }
- void get(int line) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement