4 ms·
>it is far from breaking the swirled CAPTCHA in 23 lines of Python Except it does break the captcha in 23 lines. I don't get your point. Why would he need to
by chmod775 14y ago
>it is far from breaking the swirled CAPTCHA in 23 lines of Python
Except it does break the captcha in 23 lines. I don't get your point.
Why would he need to do any 'un-swirling' in the first place? That's not the point of the captcha. The captcha provides you with multiple images and you have to pick the least swirled one - which is exactly what his code does.
And you argue that because he did use external libraries it's not 23 lines of python. Of course it is. He had to write only 23 lines that make up the logic to break the captcha. If you'd argue that one would have to add any previous work (or lines) done by other people to the linecount of your own project, I could also argue that 'print("Hello")' is not one line of python, because it uses some standard python library, which in turn calls native code, that native code would make a few syscalls and at some point resulting in multiple hundred lines of compiled kernel C code being executed.
So the linecount of his 23 lines python script would actually be:
23 lines of python + various libraries + the entire Linux kernel = roughly 20 million lines of code.
Good job.
And yes, that was nitpicking. And I'm angry for some reason.
- cidquick 14y agoWell put. The title is indeed completely factual! Including '23 lines' was just to let people know at first glance that the solution is simple. > If you had to write the un-swirling, gray-scaling, Sobel filtering and summation code in Python you'd be looking at a much larger pile-o-code I would also like to point out these are also all very simple operations, which would only take a few lines of Python/C/whatever to do. Python just happens to have a pre-written libraries to save reinventing the wheel.
- robomartin 14y ago> I would also like to point out these are also all very simple operations, which would only take a few lines of Python/C/whatever to do. Yikes! They are not. That's a lot of code. I've done a ton of image processing work in both hardware (FPGA) and software (various languages). Swirling, gray-scaling, Sobel filtering and summation collectively are far from "a few lines of Python/C/whatever to do" > Python just happens to have a pre-written libraries to save reinventing the wheel That's not true. OpenCV is NOT a Python library, it's nearly 100% C++ as far as I can tell: https://github.com/Itseez/opencv https://github.com/Itseez/opencv That was, in many ways, my point. This is not a solution in 23 lines of Python. Go install Python from Python.org --and NOTHING ELSE-- and solve the problem. Let's see how many lines of Python it takes. There's nothing wrong with the intent of the author in terms of showing how one can break these CAPTCHA's using edge-length evaluation. I never put any thought into this myself so, yes, I learned something of value from his post. I just wish the title was more genuine, that's all.
- cidquick 14y agoMy turn to nitpick! RGB to grayscale: V = r x g x b/3 (one line). The Sobel operation is at most 4 nested loops (really only 3) for a total of ~7 lines of code, depending on how you like your white space. Fold the summation into your Sobel function without requiring another line. The most complicated thing used from the OpenCV library (which I'm well aware is C++!) is JPEG decoding. OK, I'm avoiding swirling, but then it isn't needed to solve the CAPTCHA anyway.
- robomartin 14y agoShow me working code and then we can talk. :) Oh, BTW, "V = r x g x b/3" is incorrect. This is not you convert a color image to a grayscale image.
- deleted 14y ago[deleted]
- chmod775 14y agoOk, I'll do. I will assume that we already have the image in an 1-dimensional array, each element containing an array of the RGB values. Then we can convert it to grayscale with one line of python. gray = map(lambda p:sum(p)/3,IMG) If you want to test it, you can use this 3x3 sample image (or just load one): IMG = [[5, 5, 5], [6, 8, 9], [94, 123, 4], [54, 5, 32], [44, 3, 3], [34, 234, 33], [5, 5, 5], [6, 8, 9], [94, 123, 4]] The result will look like this: [5, 7, 73, 30, 16, 100, 5, 7, 73] If your image happens to be loaded into a 2-dimensional array, use this: gray = map(lambda row:map(lambda p:sum(p)/3,row), IMG) Sobel is slightly more complicated, but can be written like this (you'll need a larger sample image though): width, height #width and height of our image IMG #2D array of our RGB values sobel #result image # The actual filter starts here: for x in range(1,width-1): for y in range(1,height-1): sx = IMG[x-1][y-1]+IMG[x][y-1]*2+IMG[x+1][y-1]-IMG[x-1][y+1]-IMG[x][y+1]*2-IMG[x+1][y+1] sy = IMG[x+1][y-1]+IMG[x+1][y]*2+IMG[x+1][y+1]-IMG[x-1][y-1]-IMG[x-1][y]*2-IMG[x-1][y+1] sobel[x][y] = Math.sqrt(sx*sx+sy*sy) A total of 5 lines. And I have to thank you, because I finally just learned what convolutions are while doing this.
- floody-berry 14y agoIf you aren't going to have a cut off point for what is considered solving the problem and what is considered ancillary, then you can define new languages where a zero byte input stands for whatever solution you want, simultaneously one-upping everyone and contributing nothing to the conversation.
- jlgreco 14y agoUnless the test of "human-ness" is the ability to drag a slider, or whoever it is that you interact with the captcha, picking the least swirled of a set of images is solving the captcha because that is the test of human-ness. This seems fairly cut and dry to me.
- robomartin 14y agoNo need to be angry. None of this is going to remove food from your table or affect your life in any way whatsoever. Take it easy. I am just opening the topic for conversation. We can discuss things without pulling out semi-automatic weapons, right? When someone publishes code and says something like "solved <problem> in <n lines> of <pick your language>" there generally is an implied "my language is better than yours" subliminal message that, for some strange reason, is based on line count. Let's not debate the merit of line count as a measure of how good a language may or may not be. If we are going to go there I'll write the same solution in APL and we'll start counting characters instead. Again, line or character count, in my opinion, is not a measure of the "superiority" of a language. The 28 line solution is not pure Python. How do we define pure Python. Let's just say that "solved <problem> in <n lines> of Python" to me means that you download and install Python: http://www.python.org/download/releases/2.7.3/ http://www.python.org/download/releases/2.7.3/ Install nothing else whatsoever and write code that solves <problem>. OpenCV, which is what the author used for a couple of aspects of this code, is an extensive (and really cool) C++ library that is being accessed from Python. Here's the source: https://github.com/Itseez/opencv https://github.com/Itseez/opencv I'll leave it up to the reader to find the source for the Sobel method. A much more honest title could have included something like "solving <problem> with <n> lines of Python using OpenCV". As I said before, the intent of the article and what is being demonstrated are good, no, great. I just wish the title was a little more reflective of reality. That's all. No need to get worked-up. This is not that serious of an issue. Just a comment.
- stch 14y agoActually, that's not entirely reflective of reality. You would have to access www.python.org in order to download python, so you'd have to write some sort of TCP/IP handler to connect to that interface...actually let me back up, you first would have to solder together a few million transistors to create a CPU before you could do that. You're making it seem way easier than it actually is, please don't go exaggerating the truth so blatantly.
- readme 14y agoSomeone has disagreed with you -- which you anticipated would happen. Therefore he must be angry? I agree with him. If it's wrapped up in a library and it's distributed by a package manager then it doesn't count towards the total SLOC of your project.