Created
July 2, 2020 10:04
-
-
Save Gu1nness/bfa3cdb9a043b94dfe4e4ab730d39e75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Author: Guinness | |
Date: 30/06/2020 | |
Licence: GPLv3 | |
""" | |
FILENAME_CRACKED = "cracked.txt" | |
FILENAME_ORIGINAL = "original.txt" | |
def parse_cracked_file(filename): | |
""" Parse the cracked file and outputs a dict. | |
""" | |
cracked_dict = {} | |
with open(filename, mode="r") as cracked_file: | |
data = cracked_file.read().splitlines() | |
for line in data: | |
splitted = line.split(":") | |
cracked_dict[splitted[0]] = splitted[1] | |
return cracked_dict | |
def parse_original_data(filename, cracked): | |
""" Parse the original file line per line, compares it to the cracked dict and outputs a dict. | |
""" | |
full_dict = {} | |
with open(filename, mode="r") as original_data: | |
for line in original_data: | |
cleaned = line.strip() | |
splitted = cleaned.split() | |
if cracked.get(splitted[1], False): | |
full_dict[splitted[1]] = (cracked[splitted[1]], splitted[0]) | |
return full_dict | |
def main(): | |
""" Main function, output everything to a file. | |
""" | |
cracked_dict = parse_cracked_file(FILENAME_CRACKED) | |
output_dict = parse_original_data(FILENAME_ORIGINAL, cracked_dict) | |
with open("full_output.txt", mode="w") as output: | |
for key, value in output_dict.items(): | |
output.write("%s:%s:%s\n" % (key, value[0], value[1])) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment