Answers for "columnar cipher"

2

python columnar cipher

def columnar_encrypt():
    plain = input("Enter the plain text: ").replace(' ', '')
    key = list(input("Enter the plain text: ").lower())
    rowSize = len((key))
    m = [(list(plain[i: i + rowSize])) for i in range(0, len(plain), rowSize)]
    for i in m:
        if len(i) != rowSize:
            while len(i) != rowSize:
                i.append('')
        print(i)
    key_sort = []
    for i in sorted(key):
        key_sort.append(key.index(i))
        key[key.index(i)] = ''
    print(key_sort)
    cipher = []
    for i in key_sort:
        for j in range(len(m)):
            if m[j][i] is not '':   
                cipher.append(m[j][i])
    return 'Cipher Text: Read if you can: {0}'.format(''.join(cipher))
Posted by: Guest on November-24-2020

Python Answers by Framework

Browse Popular Code Answers by Language