Advertisement
kingbode

Untitled

Oct 14th, 2022 (edited)
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. import random
  2. from string import ascii_lowercase
  3.  
  4. msg = 'rfkkrnotmjchhddukwsgmcpkfwnsvunmvbndnjuarrnsosihwgyrgg'
  5.  
  6. def decrypt(msg):
  7.     decrypted = ''
  8.     for i in range(0, len(msg), 3):
  9.         decrypted += chr(ord(msg[i]) + ord(msg[i+1]) - ord(msg[i+2]))
  10.     return decrypted
  11.  
  12.  
  13. def encrypt(msg):
  14.     encrypted_message = ''
  15.     for char_ in msg:
  16.                 # for each character generate 3 characters randomly where adding unicode values of first 2 chars and subtracting third to get unicode value of letter
  17.         # just pick 2 random characters and deduce the third one using the original character in the message
  18.         temp_chars = ''
  19.         while True:
  20.             temp_chars += random.choice(ascii_lowercase)
  21.             if len(temp_chars) == 2:
  22.                 temp_chars+= chr(ord(temp_chars[0]) + ord(temp_chars[1]) - ord(char_))
  23.                 break
  24.  
  25.         encrypted_message += temp_chars
  26.  
  27.     return encrypted_message
  28.  
  29.  
  30.  
  31. decrypted_message = decrypt(msg)
  32.  
  33. print(decrypted_message)
  34.  
  35. encrypted_message = encrypt(decrypted_message)
  36.  
  37. print(f'another equivalent encrypted message : {encrypted_message}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement