Last active
June 5, 2018 07:45
-
-
Save a3linux/4576c43d310ab036d40e17d17fd0221a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 python | |
| import argparse | |
| import base64 | |
| def encode(key, string): | |
| encoded_chars = [] | |
| for i in xrange(len(string)): | |
| key_c = key[i % len(key)] | |
| encoded_c = chr(ord(string[i]) + ord(key_c) % 256) | |
| encoded_chars.append(encoded_c) | |
| encoded_string = "".join(encoded_chars) | |
| return base64.urlsafe_b64encode(encoded_string) | |
| def decode(key, encrypted_pass): | |
| dec = [] | |
| enc = base64.urlsafe_b64decode(encrypted_pass) | |
| for i in range(len(enc)): | |
| key_c = key[i % len(key)] | |
| dec_c = chr((256 + ord(enc[i]) - ord(key_c)) % 256) | |
| dec.append(dec_c) | |
| return "".join(dec) | |
| if __name__ == "__main__": | |
| DEFAULT_PASS = "PASS" | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--passcode", "-c", dest="passcode", default=DEFAULT_PASS, | |
| help="Encrypt Passcode, default is PASS") | |
| parser.add_argument("--password", "-p", dest="password", required=True, | |
| help="Password to encrypt") | |
| parser.add_argument("--decrypted", "-d", dest="is_decrypt", default=False, | |
| action="store_true", help="Decrypt action") | |
| args = parser.parse_args() | |
| if args.is_decrypt: | |
| print("%s decrypted is: %s" % ( | |
| args.password, decode(args.passcode, args.password) | |
| )) | |
| else: | |
| print("%s encrypted is: %s" % ( | |
| args.password, encode(args.passcode, args.password) | |
| )) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment