Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from string import ascii_lowercase
- msg = 'rfkkrnotmjchhddukwsgmcpkfwnsvunmvbndnjuarrnsosihwgyrgg'
- def decrypt(msg):
- decrypted = ''
- for i in range(0, len(msg), 3):
- decrypted += chr(ord(msg[i]) + ord(msg[i+1]) - ord(msg[i+2]))
- return decrypted
- def encrypt(msg):
- encrypted_message = ''
- for char_ in msg:
- # for each character generate 3 characters randomly where adding unicode values of first 2 chars and subtracting third to get unicode value of letter
- # just pick 2 random characters and deduce the third one using the original character in the message
- temp_chars = ''
- while True:
- temp_chars += random.choice(ascii_lowercase)
- if len(temp_chars) == 2:
- temp_chars+= chr(ord(temp_chars[0]) + ord(temp_chars[1]) - ord(char_))
- break
- encrypted_message += temp_chars
- return encrypted_message
- decrypted_message = decrypt(msg)
- print(decrypted_message)
- encrypted_message = encrypt(decrypted_message)
- print(f'another equivalent encrypted message : {encrypted_message}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement