You are on page 1of 2

#!

/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'encrdecr' function below.
#
# The function is expected to return a LIST.
# The function accepts following parameters:
# 1. STRING keyval
# 2. STRING textencr
# 3. Byte-code textdecr
#

from cryptography.fernet import Fernet


def encrdecr(keyval, textencr, textdecr):

l1=[]
f=Fernet(keyval)
l1.append(f.encrypt(textencr))
l1.append(f.decrypt(textdecr).decode())
return l1

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

file = open('key.key', 'rb')


key = file.read() # The key will be type bytes
file.close()

keyval = key

textencr = str(input()).encode()

textdecr = str(input()).encode()

result = encrdecr(keyval, textencr, textdecr)


bk=[]
f = Fernet(key)
val = f.decrypt(result[0])
bk.append(val.decode())
bk.append(result[1])

fptr.write(str(bk) + '\n')

fptr.close()
'''

This text is to be encrypted with cryptography module


gAAAAABe2LzlIGxTehNE5gqwgDzJb_5y72fKiFhNwjuIGWCN1KSUrLXiq8rV3p4ZRmK-
km6JI9oezOgGG0nIp8r6KejTcn09J70bVJ6Y04h0w8zztr9w9Ts=
['This text is to be encrypted with cryptography module', 'my deep dark secret']

The Earth is a beautiful place to live


gAAAAABe2Mc0umqGP-
nA6qNyTKsN9h49KuEKtVvec_6F2WJE2HCHYRdNG5PDsTHmUNoR9XCpaQkHz9N1hKPhoAC9TjGzTAbM0w97p
vQVM2uz-3QaPiVEzDhUodcaNE_Fw6rouhD88Pd0

['The Earth is a beautiful place to live', 'The Earth is a beautiful place to


live']'''

You might also like