Building an invalid string in Python 2.x
gist.github.com
gist.github.com
http://hg.python.org/cpython/file/tip/Objects/unicodeobject....
CPython supports several internal representations from one to four bytes per character to optimize for space and performance. There's also a nifty sort of Bloom filter for quick discrimination of strings that might contain characters of interest.
I hope I never forget about changing them back and end up having to debug two different machines with the same MAC (which has actually happened to me in the wild, with two machines coming out of factory with the same MAC, talk about bad luck and shitty quality control).
The magic number that identifies a java .class file is 0xCAFEBABE.
< /usr/share/dict/words perl -ne 'print if m/^[abcdefilzsbtgo]*$/ && m/^........$/;' | perl -ne 'print if !(m/i/ && m/l/);' | tr 'ilzstgo' '1125790' | tr '[:lower:]' '[:upper:]' | perl -ne 'print "0x$_"' | column
< /usr/share/dict/words perl -ne 'next unless m/^[abcdefilzsbtgo]*$/ && m/^........$/; next unless !(m/i/ && m/l/); chomp; print "$_ "; $_ =~ tr/ilzstgo/1125790/; print "0x$_\n"' | column
This adds the original word to the left of the hex. It makes the list much more scannable.
Tweaking the dots to count 10 shows that there are apparently 33 choices for WEP codes, if you are so inclined. (Which of course you shouldn't be, but, well...) And, alas, there do not appear to be any 64-bit constants according to my dictionary, though there's enough 32-bit coices to have some fun with phrases ("collated catcalls", "sadistic sabotage", "fattiest feedbags", "besotted ascetics", etc.). And that's just the even 8-8 phrases, 9-7 has almost as many ("godless geodesics", "falsest statistic", 0x7a55e11edb00b1e5).
Thank dhart for an introduction to the "< /file program" idiom that puts file first without resorting to cat, and for column for that matter. Neat. In return I'll offer perl's new /r flag which "returns" the result of tr// or s/// rather than some count.
The only place UTF-7 is still widely used is in email clients.
Hmm, may I ask what makes utf8 won't produce U+DEADBEEF? Or something remotely like that?
Edit:
'\xfb\x9b\xbb\xaf'.decode('utf8')
UnicodeDecodeError: 'utf8' codec can't decode byte 0xfb in position 0: invalid start byte
When Unicode was deemed to end at U+10FFFF (because that's the largest value that UTF-16 can encode), UTF-8 was revised to be a 1-4 byte encoding that ends in the same place.
Python clearly implements UTF-8 in a way that uses at most four bytes per codepoint (why support five and six byte sequences if they'll never be used?). I think what we're seeing in '\xfb\x9b\xbb\xaf' is four bytes out of a six byte sequence.
http://en.wikipedia.org/wiki/G%C3%B6del's_incompleteness_the... http://www.amazon.com/G%C3%B6del-Escher-Bach-Eternal-Golden/...
Well, the comments state that to make this happen he had to "[exploit] a bug in the UTF-7 decoder". So, not legal assertions.