Tags: misc python programming
Rating: 4.0
You get ten copies of *Sentimental Education: The Story of a Young Man*
with a certain difference between them.
![https://github.com/n00bSec/n00bSec.github.io/raw/master/pics/DefCamp/DefCampCTFStoryOfAYoungMan.png](http://)
The flag is in each of these differences. I didn't want to reinvent the wheel, since Python's so good already for analyzing texts,
so I at least did enough Googling to find out about difflib. I then spent a little time hacking together soln.py...
```
#!/usr/bin/python
import difflib
from subprocess import Popen, PIPE
files = [(str(i).rjust(4, '0') + '.txt') for i in range(1,11)]
output_lines = []
for f1 in range(len(files)-1):
f2 = f1+1
p = Popen(['diff', files[f1], files[f1+1]], stdout=PIPE)
lines = p.stdout.readlines()[1::2]
for line in lines:
output_lines.append(line)
guess = ''
#Each of these sections look breakable into fours
for i in range(0,len(output_lines),2):
print str(i) + "..."
original = output_lines[i][2:]
replaced = output_lines[i+1][2:]
print original
print replaced
diff = ''
for x in difflib.ndiff(original[2:],replaced[2:]):
if x.startswith('+'):
diff += x[2:]
print diff.replace(' ','')
guess += diff.replace(' ','')
print "This your flag?: " + guess # DCTF{7ba610cc5da3966b7c64a81c3cfcdb1b1d09e3de5ad1189268bf0e618ff71f08}'
```