(27-06-2025, 11:08 AM)quimqu wrote: You are not allowed to view links. Register or Login to view.I attach the function to cipher:
def homophonic_cipher_3c(words):
letter_map = {c: [c + str(i) for i in range(3)] for c in 'abcdefghijklmnopqrstuvwxyz'}
out = []
for word in words:
new_word = ''.join(random.choice(letter_map.get(c, [c])) for c in word)
out.append(new_word)
return out
It's a simple homophonic cipher. First creates a letter map for each alphabetical character (so, each letter will have three different letters to choose randomly during the cipher).
Thanks for the explanation. So the letter "l" is ciphered either as "l0", "l1" or "l2", only the digit is chosen randomly. This is not a homophonic cipher: the digits are all nulls.
Code:
import random
def homophonic_cipher_3c(words):
letter_map = {c: [c + str(i) for i in range(3)] for c in 'abcdefghijklmnopqrstuvwxyz'}
out = []
for word in words:
new_word = ''.join(random.choice(letter_map.get(c, [c])) for c in word)
out.append(new_word)
return out
pt = input('Enter plaintext: ')
print(f'Ciphertext of plaintext "{pt}" is {homophonic_cipher_3c(pt)}')Ciphertext of plaintext "tell me more" is ['t0', 'e2', 'l2', 'l0', ' ', 'm0', 'e2', ' ', 'm1', 'o1', 'r2', 'e1']

