ProjectDevelopment

When Your Laptop Gets Locked: How I Built a Visual Data Transfer System Using OCR and ASCII Art

When my work laptop got remotely locked with a week's worth of uncommitted code, I built an unconventional solution using a webcam and ASCII art to transfer 7,000 lines of code between machines.

17 views

The Day Everything Went Wrong

Picture this: You've been working on a critical feature for over a week. Seven thousand lines of carefully crafted code, sitting on your laptop, just about to be committed. You're literally reaching for the keyboard to type git push when suddenly—boom. Your screen flashes, and your laptop is locked. Not just locked—completely isolated.

No USB ports. No WiFi. No Bluetooth. Nothing. It's like your machine just became a very expensive paperweight with a screen.

Yeah, that was me a few months ago. My company's IT department had remotely locked my laptop for security reasons (don't ask), and there I was, staring at a week and a half of undeployed changes that existed nowhere else but on that locked machine. I had, to put it mildly, a very bad day.

But here's the thing about developers—we're problem solvers (and lazy folk) by nature. And as I sat there, contemplating my life choices, a thought struck me: "I can still see the code, can't I?"

From Desperation to Innovation

Now, before you say it—yes, I considered manually retyping 7,000 lines of code. For about three seconds. Then my engineering brain kicked in with a better question: "If I can see it, can I automate copying it?"

The solution seemed obvious at first: Optical Character Recognition (OCR). I'd use a webcam on another machine to "read" the code from my locked laptop's screen. Simple, right?

I fired up Python, imported some OCR libraries, connected my webcam, pointed it at the locked screen, and... it was a disaster. The accuracy was terrible. Code has special characters, specific formatting, and precise indentation that standard OCR just couldn't handle reliably. Characters like { and ( were constantly confused, and don't even get me started on trying to distinguish between 0 and O.

AI generated image for illustration purposes since I couldn't find a dramatic enough one

AI generated image for illustration purposes since I couldn't find a dramatic enough one

But here's the trick—when the data is too complex, make it simpler.

The ASCII Art Solution

Instead of trying to make OCR understand complex code syntax, what if I converted my data into something much simpler to recognize? Enter: ASCII art data encoding.

I really do seem to love ASCII, don't I?
Me, for those who know

I created a system that would represent each character as a pattern of X characters in a matrix. Think of it like a simplified QR code:

  • "A" became "#"
  • "B" became "# #"
  • "E" became "# # # # #"
  • And so on...

This approach was genius (if I do say so myself). The webcam and OCR only needed to recognize two things: spaces and # symbols (which we no longer treat as a symbol, just a "something" in the image that we need to count). The accuracy shot up dramatically, and suddenly I was successfully transferring data between machines using nothing but visual recognition.

I was hyped! Until I hit the next problem...

The Duplicate Frame Challenge

Webcams capture multiple frames per second, and my receiving program had no way to know when a character display had changed. If the same character stayed on screen for six frames, it would be written six times. Hello became HHHHHHeeeeeellllllllllllooooo.

Not ideal.

So I improved it again. I introduced escape characters to handle duplicates and transitions. And because why not add some flair to an already unconventional solution, I used Chinese characters as markers. They were visually distinct enough that the OCR would never confuse them with my ASCII patterns.

These markers served double duty—they indicated character duplicates and file boundaries. The system could now automatically detect when one file ended and another began. It was actually working!

The actual setup

The actual setup

Making It Work in Practice

The resulting final setup was beautifully simple yet surprisingly effective:

On the locked machine: A Python script that read my code files and displayed them as ASCII art patterns on the screen, complete with escape characters for duplicates and file markers.

On the receiving machine: Another Python script connected to a webcam, watching the locked machine's screen, decoding the patterns, and reconstructing the original files.

Was it elegant? Not particularly. Was it fast? Definitely not—transferring 7,000 lines took hours. But did it work? Abso-freaking-lutely.

I did not copy the files, that would be inefficient. I copied the git log, and used it to restore the changes on my other PC

The locked machine's program was intentionally kept simple. While I used Python, it could have been implemented in bash or any default language available on the system. The beauty was in its simplicity—no network access required, no USB ports needed, just a screen and the ability to display characters.

If you can do it yourself, chances are, you can automate it.

Lessons Learned and Open Source

This experience taught me several valuable lessons:

  • 1. Constraints breed creativity. Having no traditional data transfer options forced me to think outside the box.

  • 2. Simple solutions often beat complex ones. ASCII art patterns were more reliable than sophisticated OCR.

  • 3. Always commit your code. Seriously. Always.

I've open-sourced the entire solution on GitHub because, honestly, you never know when someone might face a similar situation. Whether it's a locked laptop, an air-gapped system, or just a fun weekend project, the code is there for anyone who needs it.

The repository includes both the sender and receiver scripts, detailed setup instructions, and even some optimizations I've added since the original incident. Feel free to star it, fork it, or suggest improvements!


So next time you're faced with an "impossible" data transfer situation, remember: if you can see it, you can probably find a way to copy it. It might involve webcams, ASCII art, and Chinese escape characters, but hey—that's what makes our job interesting, right?

Have you ever had to come up with an unconventional solution? I'd love to hear your stories in the comments below. And seriously, commit your code regularly. Learn from my mistake!

Pablo Dominguez

Pablo Dominguez

Full Stack Developer passionate about building interesting projects and learning new skills.

Stay Updated

Subscribe to get notified about new blog posts and projects.

What would you like to receive?