Decoding a Binary text with chatgpt
Schuberg Philis

Decoding a Binary text with chatgpt

Thursday 20th April Schuberg Philis organised a tech-market to show and share knowledge between colleagues and customers. The cloud solutions around: AWS, Azure, our SBP.Cloud

Today i saw this Linked-in Post and i thought, let's try chatgpt and see if it's faster then manual decoding.



Ask ChatGPT

I have a picture with binary code in numbers, how can i convert this into text?


The answer came instant:

To convert a picture with binary numbers into text, you can use Optical Character Recognition (OCR) to extract the binary numbers from the image and then convert them to text. Tesseract OCR is a popular OCR engine that you can use for this purpose. Here's how you can do it using Python:

  1. Install the Tesseract OCR engine. For instructions on how to install Tesseract for your operating system, please refer to the official installation guide.
  2. Install the pytesseract and Pillow libraries:

pip install pytesseract Pillow         

  1. Create a Python script to read the image, extract the binary numbers using OCR, and convert them to text:

import pytesseract
from PIL import Image


def image_to_binary(image_path):
? ? img = Image.open(image_path)
? ? binary_code = pytesseract.image_to_string(img, config='--psm 6 -c tessedit_char_whitelist=01')
? ? return binary_code


def binary_to_text(binary_code):
? ? text = ""
? ? binary_code = binary_code.replace(" ", "").replace("\n", "")? # Remove spaces and newlines
? ? for i in range(0, len(binary_code), 8):
? ? ? ? byte = binary_code[i:i + 8]
? ? ? ? text += chr(int(byte, 2))
? ? return text


image_path = "path/to/your/image.png"? # Replace this with the path to your image file
binary_code = image_to_binary(image_path)
text = binary_to_text(binary_code)
print(text)        

Replace "path/to/your/image.png" with the actual path to your image file. This script reads the image, extracts the binary numbers using Tesseract OCR, and then converts the binary numbers to text. Note that this script assumes that the binary code in the image consists of 8-bit ASCII characters. You may need to adjust the script based on your specific image and encoding.

Keep in mind that OCR may not be 100% accurate, especially if the image quality is low or the text is distorted. In such cases, you might need to preprocess the image to improve OCR accuracy, such as resizing, thresholding, or denoising the image.


Let's try it.

Install Tesseract

First step, let's open the tesseract link and try to find how to install it on my mac.

Seems like i need to go to Compiling & Installation, then click on installation. Find the Mac section. Then search more for the homebrew part.

brew install tesseract        

Took me some time, but not very user-friendly.

Let's try ChatGpt

how do install tesseract on mac

To install Tesseract OCR on macOS, you can use the Homebrew package manager. If you don't have Homebrew installed, follow the installation instructions on the Homebrew website.

Once you have Homebrew installed, open a terminal and follow these steps:

  1. Update Homebrew to ensure you have the latest package information:

brew update         

  1. Install Tesseract OCR:

brew install tesseract         

This command installs the Tesseract OCR engine on your macOS system.


Same question on google:

Instructions

  1. To install tesseract, run the following command in macOS terminal (Applications->Utilities->Terminal) sudo port install tesseract Copy.
  2. To see what files were installed by tesseract, run: port contents tesseract Copy.
  3. To later upgrade tesseract, run: sudo port selfupdate && sudo port upgrade tesseract Copy.

This works if you have macports installed. Most people are using homebrew.

Python Libraries

pip install pytesseract Pillow         

I'm working with python on a daily base, but this will work for most people.


Running the Code

I saved the code in a file called decode.py

Downloaded the image from the browser and saved it in the same folder as the decode.py.

python decode.py        

Error... FileNotFoundError: [Errno 2] No such file or directory

My mistake, i forgot the read the steps to actually open the decode.py and change the name of the image.


Success!

python decode.py
I was at Schuberg Philis and I liked it!

        

要查看或添加评论,请登录

Jacob Verhoeks的更多文章

  • Am i threatened by ChatGPT?

    Am i threatened by ChatGPT?

    As someone who loves to read, learn, and be the go-to person for answers to all kinds of technology questions, the rise…

社区洞察

其他会员也浏览了