Torsional buckling and writhing dynamics of elastic cables and DNA