0% found this document useful (0 votes)
46 views3 pages

Untitled3 - Jupyter Notebook

81819jsjisjjajajkakkka hajia

Uploaded by

anuthefab.1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views3 pages

Untitled3 - Jupyter Notebook

81819jsjisjjajajkakkka hajia

Uploaded by

anuthefab.1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

28/10/2024, 10:55 Untitled3 - Jupyter Notebook

In [1]: from cryptography.fernet import Fernet



# Define the encryption key and encrypted text
key = "0N6T-k1_jcEQr-IS3aU4icONPn8EKivu732ER4Fz4LM="
encrypted_text = """
gAAAAABnHw0r2ME3MmocosMKE-SRAy4nl2qv4NMhj9m9PW9O-PWF4tiA71wVXvUPIHbWmssQbev-Sp
"""

# Convert key and text to byte strings
key_bytes = key.encode()
encrypted_bytes = encrypted_text.encode()

# Initialize the Fernet object and decrypt the text
fernet = Fernet(key_bytes)
decrypted_text = fernet.decrypt(encrypted_bytes).decode()

print("Decrypted Text:", decrypted_text)

Decrypted Text: nine five seven three zero eight five U+1F602 U+1F604 nine f
ive seven U+1F604 six U+1F600 five seven U+1F604 zero five U+1F601 seven U+1
F600 three U+1F605 U+1F602 U+1F603 nine U+1F603 four three three U+1F603 U+1
F603 zero one six seven U+1F601 nine one U+1F604 eight U+1F604 U+1F601 five
seven six nine seven U+1F606 U+1F60D U+1F923 zero eight U+1F602 two four thr
ee nine U+1F642 U+1F602 U+1F600 six eight U+1F605 nine U+1F606 two six U+1F6
04 U+1F60D nine zero U+1F923 two U+1F603 three U+1F604 U+1F606 U+1F602 nine
U+1F60D U+1F642 U+1F606 U+1F603 U+1F601 U+1F642 U+1F604 U+1F642 U+1F604 thre
e two U+1F923 eight two five U+1F602 U+1F605 U+1F600

localhost:8888/notebooks/Untitled3.ipynb?kernel_name=python3# 1/3
28/10/2024, 10:55 Untitled3 - Jupyter Notebook

In [2]: import re

# Decrypted text
decrypted_text = """
nine five seven three zero eight five U+1F602 U+1F604 nine five seven U+1F604
"""

# Function to replace Unicode emoji codes with actual emojis
def replace_unicode_with_emoji(text):
# This regex finds all Unicode emoji representations (like U+1F602)
emoji_unicode_pattern = re.compile(r'U\+([0-9A-Fa-f]+)')

# Replace the found Unicode with the actual emoji


def unicode_to_emoji(match):
unicode_value = match.group(1)
return chr(int(unicode_value, 16))

return emoji_unicode_pattern.sub(unicode_to_emoji, text)



# Replace number words with actual numbers
def word_to_number(text):
words_to_numbers = {
'zero': '0', 'one': '1', 'two': '2', 'three': '3', 'four': '4',
'five': '5', 'six': '6', 'seven': '7', 'eight': '8', 'nine': '9'
}

words = text.split()
result = [words_to_numbers.get(word, word) for word in words]
return ' '.join(result)

# Replace the emoji Unicode representations
decrypted_with_emojis = replace_unicode_with_emoji(decrypted_text)

# Replace number words with actual digits
final_text = word_to_number(decrypted_with_emojis)

# Print the final decrypted text with emojis
print(final_text)

9 5 7 3 0 8 5 😂 😄 9 5 7 😄 6 😀 5 7 😄 0 5 😁 7 😀 3 😅 😂 😃 9 😃 4
3 3 😃 😃 0 1 6 7 😁 9 1 😄 8 😄 😁 5 7 6 9 7 😆 😍 🤣 0 8 😂 2 4 3 9
🙂 😂 😀 6 8 😅 9 😆 2 6 😄 😍 9 0 🤣 2 😃 3 😄 😆 😂 9 😍 🙂 😆 😃
😁 🙂 😄 🙂 😄 3 2 🤣 8 2 5 😂 😅 😀

localhost:8888/notebooks/Untitled3.ipynb?kernel_name=python3# 2/3
28/10/2024, 10:55 Untitled3 - Jupyter Notebook

In [5]: from cryptography.fernet import Fernet



# Function to generate a new encryption key (keep this key safe for decryption
def generate_key():
return Fernet.generate_key()

# Function to encrypt the message
def encrypt_message(message, key):
# Create a Fernet cipher using the provided key
cipher = Fernet(key)
# Convert the message to bytes and encrypt it
encrypted_message = cipher.encrypt(message.encode())
return encrypted_message

# Function to decrypt the message (for testing)
def decrypt_message(encrypted_message, key):
cipher = Fernet(key)
decrypted_message = cipher.decrypt(encrypted_message)
return decrypted_message.decode()

# Example usage:
if __name__ == "__main__":
# The message to be encrypted (with emojis)
message = "9 5 7 3 0 8 5 😂 😄 9 5 7 😄 6 😀 5 7 😄 0 5 😁 7 😀 3 😅

# Generate a key (this should be stored securely)
key = generate_key()
print(f"Generated Key: {key.decode()}")

# Encrypt the message
encrypted_message = encrypt_message(message, key)
print(f"Encrypted Message: {encrypted_message.decode()}")

Generated Key: aFEmBB35kLSqLTktX1R5_COG__zTytgLckswpuVBepU=


Encrypted Message: gAAAAABnHx2cXsf7lFlmv94O3ee0BbcIjdH4t3nguoENoe8sxgGCYcqKM
VrV7ObWUJtSgf4uAAmJIgluSQFiAtzlMENEieMB7QYvhzuPREv-xIgt8IBk2QPaAQH20Elh9UowF
-JI9c6kuRJw-LmCfb5Fwmaoqji7oSLyLygtT8PjNUaHTnM5diuR26Q4xjOP9068rXPy1YsC_KuGb
V_0jJrGHGkILEU9bfUwzceiXgPkMDwqWQ6lUqQPZB3DzoM-6Ls5nZEubJRZ6Wu4o9qij-oorO4Mf
Jlae0AVXvXiqiuoA1sL86Gw1w_RBApn5ufcvOQlMyVI1CmCBK-nSSBHCgwig7Cckg6-KULo17eEb
FSjkyi3uHD7zsEwOMiup-FVQw3R75XPAs-5qnxQQDTCBB4aEaF8ADuGjYFW7I1l8Qhgw1hIVBKwz
JUf1GIaTTnn67-OBiUou_egrPXxpyXTw1Sruec-UccmBQzfhVvBQDNmA0R1T2KQyiSy9YPFbJtEQ
_bh9Fe5bpc_IRRE3GFN6rXWHhMPdKFh9A==

In [ ]: ​

localhost:8888/notebooks/Untitled3.ipynb?kernel_name=python3# 3/3

You might also like