The Diff Match and Patch libraries offer robust algorithms to perform the operations required for synchronizing plain text.
diffmatchpatchtext-processingdifference
https://github.com/google/diff-match-patch