import string
import math
import itertools


class CryptoSquare:

    @classmethod
    def encode(cls, msg):
        if len(cls.normalize(msg)) == 0:
            return ''
        return ' '.join(cls.transpose_square(cls.squarify(cls.normalize(msg))))

    @classmethod
    def squarify(cls, msg):
        return [msg[i:i + cls.square_size(len(msg))]
                for i in range(0, len(msg), cls.square_size(len(msg)))]

    @classmethod
    def transpose_square(cls, square):
        matrix = [list(row) for row in square]
        transposed_matrix = cls.transpose_uneven_matrix(matrix)
        joined_matrix = [''.join([x for x in row if x is not None]) for row in transposed_matrix]
        return joined_matrix

    @staticmethod
    def normalize(msg):
        return ''.join(ch.lower() for ch in msg if ch not in
                       set(string.punctuation + ' '))

    @staticmethod
    def square_size(msg_length):
        return int(math.ceil(msg_length ** 0.5))

    # https://stackoverflow.com/a/4938130/2813210
    @staticmethod
    def transpose_uneven_matrix(matrix):
        return list(itertools.zip_longest(*matrix))

def encode(msg):
    return CryptoSquare.encode(msg)

@@ -548,16 +548,36 @@
 atrix = 
+cls.filter_out_none(
 cls.tran
@@ -603,16 +603,17 @@
 (matrix)
+)
 %0A       
@@ -617,66 +617,40 @@
     
-joined_matrix = %5B''.join(%5Bx for x in row if x is not None%5D
+transposed_square = %5B''.join(row
 ) fo
@@ -696,21 +696,25 @@
 urn 
-joined_matrix
+transposed_square
 %0A%0A  
@@ -1132,16 +1132,143 @@
 trix))%0A%0A
+    @staticmethod%0A    def filter_out_none(matrix):%0A        return %5B%5Bval for val in row if val is not None%5D for row in matrix%5D%0A%0A
 def enco

Refactor filter out none to method