Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import hashlib
- import os
- from datetime import datetime
- import getpass
- def pretty_time(t):
- return str(t.date()) + " " + str(t.hour) + "-" + str(t.minute) + "-" + str(t.second)
- if not os.path.isfile("input.txt"):
- open("input.txt", "w").write("Write your input here")
- print("Please open the input.txt file")
- exit()
- input_text = open("input.txt", "r").read()
- username = input("Username : ")
- password = getpass.getpass("Password : ")
- key = hashlib.sha256( (username + "." + password).encode("utf-8") ).hexdigest()
- print("\nInput : ")
- print(input_text, "\n")
- print("Decode / Encode?")
- action = ""
- while action != "decode" and action != "encode":
- action = input("Action : ").lower()
- if action != "decode" and action != "encode":
- print("Invalid action")
- output = ""
- for i in input_text:
- if ord(i) > 31 and ord(i) < 127:
- value = ord(i) - 32
- if action == "encode":
- output += chr((value + int(key, 16)) % 95 + 32)
- elif action == "decode":
- output += chr( (value - int(key, 16)) % 95 + 32 )
- key = hashlib.sha256(key.encode("utf-8")).hexdigest()
- save_file = ""
- while save_file != "y" and save_file != "n":
- save_file = input("Save output as a file? (Y/N) : ").lower()
- if save_file != "y" and save_file != "n":
- print("Invalid input")
- if save_file == "y":
- output_dir = pretty_time(datetime.now()) + ".txt"
- output_file = open(output_dir, "w")
- output_file.write(output)
- print("Output saved at : " + output_dir)
- print(output)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement