Let the corners of the square be at (0,0),(1,0),(1,1), and (0,1).
The solution is to dig the following ditches:
Where x = (3-sqr(3))/6 =~ 0.2113248654
The total length of all ditches is aproximately 2.6389584338