Hello all, I am learning clojure by building a fuzzer but am having some trouble finding a good solution to mutating the string inputs. For a little background the most successfull fuzzers use really basic techniques that flip bits and bytes.
I know there are bit-flip functions but they don't seem to work on strings, understandably.
So I'm thinking I convert the ascii to binary, transform, and convert back to ascii.
For example, If I'm bit flipping "test"
01110100 01100101 01110011 01110100 = "test"
11110100 01100101 01110011 01110100 ;flipping the first bit
10110100 01100101 01110011 01110100 ;flipping the two first bits
I would also like to flip entire bytes so
01110100 01100101 01110011 01110100 = "test"
10001011 01100101 01110011 01110100 ;flipping the byte
My approach is coverting a strings to binary:
(defn encode [s]
"test" -> \"01110100 01100101 01110011 01110100""
(trim (cl-format nil "~{~8,'0b ~}" (map #(int %) s))))
Looping through the string and flipping the bits somehow then converting back.
I've been struggling all day for a good approach but I wanted to see if you experts had a more elegant solution.
Also interested in doing this to ints, but not sure how to best use the (Integer/toBinaryString) function
for example
(Integer/toBinaryString 87)
=> "1010111"
But since it's a string I can't do the (bit-flip) or related library functions.
Thanks in advance everyone!