Nov-17-2020, 04:27 PM
(This post was last modified: Nov-17-2020, 04:27 PM by hhydration.)
def affine_n_encode(text, n, a,b): ngraphs=[] nums=[] texts=[] if len(text) % n==0: for i in range(len(text)): ngraphs.append(text[i:i+n]) else: list(text) text.append(['x']*(len(text)%n)) ''.join(text) ngraphs.append(text[i:i+n]) for n_graph in ngraphs: nums.append(convert_to_num(n_graph)) for num in nums: texts.append(convert_to_text(((a*(num)+b)%26),n)) ''.join(texts) return texts text = "THEQUICKBROWNFOXJUMPEDOVERTHELAZYDOG" enc = affine_n_encode(text, 5, 347, 1721) print(enc)Edit: Please let me know if you need any more information about the function to understand the problem