• + 0 comments

    python

    def encryption(s):
        # Write your code here
        s = s.replace(' ', '')
        length = len(s)
        col = math.ceil(length ** 0.5)
        row = math.ceil(length / col)
        encrypted = ''
        
                
        while col * row < length:
            if (col + 1) * row <= length:
                col += 1
            else:
                row += 1
        
        added = []
        for i in range(row + 1):
            a = ''
            for j in range(0, length, col):
                if i+j < length and i+j not in added:
                    print(i, ' j=', j, ' i+j= ', i+j)
                    a += s[i+j]
                    added.append(i+j)
                    
            encrypted += a + ' '
            
        return encrypted