Created
August 7, 2018 06:53
-
-
Save mayankdiatm/ce318ecca294074655e6bdd4b3b29ef1 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
####### Search and Match Files in a directory ####### | |
os.chdir(path) | |
""" take list of all files present | |
in the directory as a list""" | |
fnames = [ | |
fname for fname in os.listdir(path) | |
if os.path.isfile(os.path.join(path, fname)) | |
] | |
print(fnames) | |
########################################################## | |
Run Shell Script via Python | |
out = subprocess.call( | |
['xyz.sh', str(var1), str(var2), str(var3), str(u), str(p)], shell=True) | |
print "printing out of shell script on console" | |
###################################################################### | |
Decrytion | |
def decrypt(ciphertext, key): | |
"""Decrypts a given ciphertext with the given key, using AES-CFB. | |
message - The ciphertext to decrypt (byte string). | |
key - The AES key (16 bytes). | |
returns The cleartext (byte string) | |
""" | |
dec = [] | |
enc = base64.urlsafe_b64decode(ciphertext) | |
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) | |
def read_details(f, s, ep): | |
bkey32 = s.ljust(32)[:32] | |
with open(f, 'r') as input_file: | |
for line in input_file: | |
if ep in line.rstrip(): | |
y = ast.literal_eval(line) | |
z = decrypt(y['password'], bkey32) | |
a = y['username'] | |
return a, z | |
######################## Encryption ######################## | |
def encrypt(message, d): | |
"""Encrypts a given message with the given key, using AES-CFB. | |
message - The message to encrypt (byte string). | |
key - The AES key (16 bytes). | |
returns (ciphertext). Both values are byte strings. | |
""" | |
encoded_chars = [] | |
for i in xrange(len(message)): | |
key_c = d[i % len(d)] | |
encoded_c = chr(ord(message[i]) + ord(key_c) % 256) | |
encoded_chars.append(encoded_c) | |
encoded_string = "".join(encoded_chars) | |
print encoded_string | |
print base64.urlsafe_b64encode(encoded_string) | |
return base64.urlsafe_b64encode(encoded_string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment