encrypt.py
# encrypt.py
#
# A simple encryption algorithm.
#
# Date: 08/02/2016
# Written By: D.Barry
#
# NOTE: Run this code in Python2.7!
import base64
def encrypt(key, msg):
encryped = []
for i, c in enumerate(msg):
key_c = ord(key[i % len(key)])
msg_c = ord(c)
encryped.append(chr((msg_c + key_c) % 127))
return base64.b64encode(''.join(encryped))
def decrypt(key, encryped):
tmp = base64.b64decode(encryped)
msg = []
for i, c in enumerate(tmp):
key_c = ord(key[i % len(key)])
enc_c = ord(c)
msg.append(chr((enc_c - key_c) % 127))
return ''.join(msg)