Skip to main content

Dynamically generated, AI-resistant captcha images

Project description

color-captcha

Dynamically generated, AI-resistant captcha images.

color-captcha

Can you tell what time it is? AI can't.

Color-captcha uses higher-order shapes to hide the information from AI. AI can recognize that the image is made up of triangles, squares and circles. However, it cannot recognize that these shapes form more complex higher-order shapes, in this case numbers. The numbers, therefore, remain hidden in plain sight. The human eye, on the other hand, should be able to see the numbers with little effort.

Features:

  • ClockCaptcha and DigitsCaptcha generators.
  • Decently performant: can generate 100 images in ~0.8 seconds.
  • Configurable (base colors, color variation).

Installation

pip install color-captcha

Usage

ClockCaptcha

from color_captcha import ClockCaptcha

captcha = ClockCaptcha(clock_mode=12, color_mode='rgb') 
# 12 or 24-hour mode
# rgb or grayscale color_mode

# current captcha value
print(captcha.value)

captcha.save_image('my_captcha.png') 
# if no extension, set format explicitly
captcha.save_image('my_captcha', format='png')

# verify the guessed value
captcha.verify('0645') 
# returns True/False

# create new captcha
captcha.generate_new()
captcha.save_image('new_captcha.png')

DigitsCaptcha

Same usage as ClockCaptcha except it generates captcha with arbitrary number of digits, and is not in the clock format, just plain digits.

from color_captcha import DigitsCaptcha

captcha = DigitsCaptcha(digits=5)
captcha.save_image('digits.png')
captcha.verify('12345')
captcha.generate_new()

Size parameter

Both ClockCaptcha and DigitsCaptcha have the size parameter, which changes the size of the image. Below relative values in pixels for the ClockCaptcha image. DigitsCaptcha images vary in width depending on the number of digits.

ClockCaptcha sizes:

size width (pixels) height (pixels)
1 190 65
2 380 130
3 (default) 570 195
4 760 260
... ... ...

Changing configuration

Configuration changes are applied globally.

  • colors: list of base colors in hex format (full 6 characters required).
  • base_variation_percent: max *variation of the color in the background.
  • content_variation_percent: max *variation of colors of the numbers.

*Percent increase of non-dominant colors in a pixel. To turn off color variation set these parameters to 0.

from color_captcha.config import Config

Config.colors = ['#ec7063', '...']
Config.base_variation_percent = 0.30
Config.content_variation_percent = 0.15

⚠️ Important to consider: Difference in color variation between background and numbers can make the numbers stand out more. If this difference is too great the AI may pick up on that and be able to detect numbers. The default values of 0.15 and 0.30 should be good for now, but may need to change in the future.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

color_captcha-0.1.5.tar.gz (33.2 kB view details)

Uploaded Source

Built Distribution

color_captcha-0.1.5-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file color_captcha-0.1.5.tar.gz.

File metadata

  • Download URL: color_captcha-0.1.5.tar.gz
  • Upload date:
  • Size: 33.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for color_captcha-0.1.5.tar.gz
Algorithm Hash digest
SHA256 9b860efd5f588a1326adc11c71db68bd6dad91d376fa1d293a9071758a5ebe4a
MD5 988313020d79c76213bf63a2df7ff32d
BLAKE2b-256 1e402b60114ec234f21d55722f12ac500a0322a005f352b7686b513ad1c9821f

See more details on using hashes here.

File details

Details for the file color_captcha-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for color_captcha-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b3c3979df3db7d4ab274f1f8a5b550ad96ba7af930dd10710c8d69789bd930c3
MD5 975eb4065277c0d4ef54cc7510226198
BLAKE2b-256 5eba66ba9c0c4bdedf2c422745aeffa91d4c77cec256662f0a297cee3dd59788

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page