diff --git a/src/undirected_graph.rs b/src/undirected_graph.rs
index bc44006847649e95c9c27e29228f1ffc3d9d35a0..3c5ad7560944b1b9d1ea5cf0ca4f6084162f8d1a 100644
--- a/src/undirected_graph.rs
+++ b/src/undirected_graph.rs
@@ -83,6 +83,33 @@ impl UndirectedGraph {
         UndirectedGraph::new(num_spokes + 1, wheel_edges)
     }
 
+    pub fn to_graph6(&self) -> String {
+        assert!(self.num_vertices <= 62);
+        let mut graph6: Vec<u8> = vec![];
+        graph6.push(self.num_vertices as u8 + 63);
+        let mut group: u8 = 0;
+        let mut idx: usize = 0;
+        for j in 1..self.num_vertices {
+            for i in 0..j {
+                if self.nauty_graph[i] & (1 << (nauty_Traces_sys::WORDSIZE as usize - 1 - j)) != 0 {
+                    group |= 1 << 5 - idx;
+                }
+                idx += 1;
+                if idx == 6 {
+                    group += 63;
+                    graph6.push(group);
+                    idx = 0;
+                    group = 0;
+                }
+            }
+        }
+        if idx > 0 {
+            group += 63;
+            graph6.push(group);
+        }
+        unsafe { String::from_utf8_unchecked(graph6) }
+    }
+
     fn induced_edge_permutation(
         g: &UndirectedGraph,
         h: &UndirectedGraph,