Skip to content

Instantly share code, notes, and snippets.

@ppetr
Created November 9, 2012 12:13
Show Gist options
  • Save ppetr/4045412 to your computer and use it in GitHub Desktop.
Save ppetr/4045412 to your computer and use it in GitHub Desktop.
Cryptographic quine - a program that prints out the MD5 sum of its source.
#!/usr/bin/env python
import hashlib
import sys
input = ['#!/usr/bin/env python', 'import hashlib', 'import sys', 'try: input', 'except NameError: input = []', 'try: trans', "except NameError: trans = lambda x: 'MD5 sum of my source is: ' \\", ' + hashlib.md5(x).hexdigest()', 'lines = input', 'lines.insert(3, "input = " + repr(input))', "out = '\\n'.join(lines) + '\\n'", 'print trans(out),']
try: input
except NameError: input = []
try: trans
except NameError: trans = lambda x: 'MD5 sum of my source is: ' \
+ hashlib.md5(x).hexdigest()
lines = input
lines.insert(3, "input = " + repr(input))
out = '\n'.join(lines) + '\n'
print trans(out),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment