s='abcb' d=0;while ~all(diag(s==rot90(s),d++)) p=[s fliplr(s(1:d))];endp
Standard input is empty
s = abcb p = abcba
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!