Code
Work on the text itself: regular expressions, two texts compared, words found by pattern or sound, word breaks put back, and words disguised by a language game’s rule.
Diff
Compares two texts by character, word or line: Myers’s algorithm (1986) finds the fewest units put in and taken out, and Levenshtein’s edit distance counts the fewest changes between them. By position it counts the letters that agree beside chance, which tells two ciphertexts under one key from two under different keys. The longest common subsequence is the core of Unix diff (Hunt and McIlroy, 1976).
History, how it works, how it was checked, limits
History
J. W. Hunt and M. D. McIlroy described Unix diff in “An Algorithm for Differential File Comparison” (Bell Laboratories, 1976). Its core is the longest common subsequence of two files, the lines both contain in the same order, which leaves what was deleted from the first and inserted in the second; E. W. Myers found it by the fewest changes in 1986.
How it works
Two texts are cut into tokens: characters (whole code points), words with the whitespace between them as tokens of their own, or lines. The shared beginning and end are set aside, and Myers’s algorithm (1986, in linear space: a search from each end until they meet, then each half alike) finds the fewest tokens deleted and inserted. Characters and words are marked inline; lines are listed with − and +. Similarity is the kept tokens over the kept and the larger of deletions and insertions. Levenshtein’s edit distance, in a card of its own, is the fewest changes that make A into B when a unit may also take another’s place; by character the texts are drawn aligned under it. By position sets the letters A–Z of the two texts place against place and counts the places that agree, beside what random letters and two English texts give, with the binomial chance of as many.
How it was checked
The tests run the tool’s own functions: kitten to sitting, a changed word and line, Myers’s Figure 1, and 5,000 seeded pairs whose kept tokens are a longest common subsequence by its table, rebuilding both texts. The edit distance equals a second, recursive reckoning on 3,000 seeded pairs, its steps make B out of A, and it keeps the triangle inequality. By position, two messages under one Vigenère key agree where their plain texts do, under different keys near one place in 26. Levenshtein’s and Wagner and Fischer’s papers are cited and were not read.
The tests hold 21 checks of this tool; 1 rests on outside material:
- A print’s own example Myers’s Figure 1: abcabba against cbabac, a common subsequence of 4 and a shortest edit script of 5 — 3 deletions, 2 insertions
Limits
The edit distance is not reckoned past four million cells of its table, and its alignment is one way of the fewest changes among several. The comparison runs off the page, for 50 million steps or five seconds at most: two long texts unlike throughout then have their middle shown all deleted and inserted, and no figure given. Tokens are compared exactly, case and every space counted, punctuation part of its word. By position reads the letters A–Z only and does not slide one text along the other.
- V. I. Levenshtein, Binary codes capable of correcting deletions, insertions, and reversals, Soviet Physics Doklady 10 (1966) — cited, not read here
- R. A. Wagner and M. J. Fischer, The String-to-String Correction Problem, Journal of the ACM 21 (1974) — cited, not read here
- J. W. Hunt and M. D. McIlroy, “An Algorithm for Differential File Comparison”, Bell Laboratories Computing Science Technical Report 41 (1976)
- E. W. Myers, “An O(ND) Difference Algorithm and Its Variations”, Algorithmica 1 (1986), pp. 251–266, §3 and §4b, “A Linear Space Refinement”