'''p = 29 q = 17 n = p*q tot = (p-1)*(q-1) e = 3 # Many present strictly for convenience's sake''' n = int(input('n: ')) e = int(input('e (make sure it\'s relatively prime to p-1 and q-1): ')) message = input('message:\n') messagenum = 0 for char in message: messagenum += ord(char) messagenum *= 128 # Assuming ASCII only characters messageblocks = [] while messagenum > 0: messageblocks.append(messagenum%n) messagenum = (messagenum-messagenum%n)//n def encrypt_block(blk): return (blk ** e) % n encrypted = [encrypt_block(block) for block in messageblocks] print(encrypted)