secrets




Pay Notebook Creator: Salah Ahmed0
Set Container: Numerical CPU with TINY Memory for 10 Minutes 0
Total0

Encrypt Messages

Steps:

  1. give your lover a secret message string
  2. enter your secret key, along with message to encrypt
  3. get ciphertext
  4. your lover will enter secret string and ciphertext, and receive your message
  5. run away together

thanks to Piotr Dabkowski and Karin

In [1]:
# Crosscompute

secret_key = 'secret key'
target_text_path= 'm.txt'
encrypt_or_decrypt_select = '''
    encrypt
    
    encrypt
    decrypt'''
target_folder = '.'
In [10]:
encrypt_or_decrypt = [x.strip() for x in 
    encrypt_or_decrypt_select.split('\n') if x.strip()][0] 
In [6]:
l = len(secret_key)
filler = '@'
accepted_lengths = sorted([16, 24, 32])
for byte_length in accepted_lengths:
    if l < byte_length:
        secret_key += (filler * (byte_length - l))
        break
else:
    secret_key = secret_key[:32]
In [7]:
from Crypto.Cipher import AES

def encrypt(k, m):
    aes = AES.new(k, AES.MODE_CFB, 'This is an IV456')
    return aes.encrypt(m)


def decrypt(k, ciphertext):
    aes = AES.new(k, AES.MODE_CFB, 'This is an IV456')
    return aes.decrypt(ciphertext)
In [8]:
from ast import literal_eval


with open(target_text_path, 'r', encoding='utf-8') as f:
    if encrypt_or_decrypt == 'decrypt':
        source = f.read()
        target_text = literal_eval("b'{}'".format(source))    
        print('plain text = %s' % decrypt(secret_key, target_text))
    else:
        target_text = f.read()
        print('ciphertext = %s' % encrypt(secret_key, target_text))
ciphertext = b'\xb3\xfd\xb3J"\x81\x9a` \xef\x1eR\xc9\x12\xe7Km\xeb5\xcd27\xe5\x0f'