Skip to main content

Generate codes

Project description

codify

Generate codes

To install: pip install codify

Qr code

from codify.qr_coding import qrcode_img_of

qrcode_img_of('https://github.com/thorwhalen')

png

And if you wanted to save that, you just do:

qrcode_img_of('https://github.com/thorwhalen').save('qr_code_of_my_website.png')

But qr codes aren't just for links. They're just a means to implement text->image->text error compressed and robust communication pipeline.

For example...

some_long_text = """Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, 
when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. 
It was popularised in the 1960s with the release of Letraset sheets containing 
Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
"""
qrcode_img_of(some_long_text)

png

Obviously, this could get out of hand.

But if all you're doing is wanting to send a fingerprint (a hash) of some text, for verification or legal purposes.

For this, you can use sha256 for example...

from codify import bytes_to_sha256
bytes_to_sha256(some_long_text.encode()).hex()
'a1a2423753693304b35308d019a37bbb12b8e8c36e07c02d1e448f28927ea557'
from codify.qr_coding import qrcode_img_of_sha256
qrcode_img_of_sha256(some_long_text)

png

Ceasar Cyphers

Tools to play with Ceasar cyphers (https://en.wikipedia.org/wiki/Caesar_cipher).

>>> from codify import ceasar_cypher
>>> ceasar_cypher("Hi, I'm Bob!")
"ij, j'n cpc!"

Note that every letter is lower-cased now. This is because ceasar_cypher preprocesses all phrases with str.lower by default. You can stop this by specifying preprocess=None, but note that, then, upper case letters won't be transformed (since they're not mapped by the default letter_transformer).

>>> ceasar_cypher("Hi, I'm Bob!", preprocess=None)
"Hj, I'n Bpc!"

The key to the cypher is letter_transformer which defines the letter mapping. The most general way to specify this is through a function, but most of the time you specify it through a mapping: an explicit {transform_this: into_this, and_this: into_that, ...} dict.

If you don't specify any letter_transformer, as above, the default is taken to be a cylclic mapping over the whole alphabet with an offset=1.

You can change that offset to another number:

>>> ceasar_cypher("Hi, I'm Bob!", letter_transformer=4)
"lm, m'q fsf!"
>>> ceasar_cypher("Hi, I'm Bob!", letter_transformer=-3)
"ef, f'j yly!"

Here's an example of specifying letter_transformer as an explicit dict:

>>> ceasar_cypher("Hi, I'm Bob!", letter_transformer={'b': 'd', 'i': 'o'})
"ho, o'm dod!"

You also have tools that will create such mappings for you, based on jumping by a fixed offset in one (mk_letter_map_from_offset) or several (multiple_cycles_letter_transformer) letter cycles. Below is an example using offset=1 on vowels and consonants separately.

>>> from codify import vowel_separated_letter_transformer
>>> vowel_separated_letter_trans = vowel_separated_letter_transformer(offset=1)
>>> list(vowel_separated_letter_trans.items())[:9]
[('a', 'e'), ('e', 'i'), ('i', 'o'), ('o', 'u'), ('u', 'a'), ('b', 'c'), ('c', 'd'), ('d', 'f'), ('f', 'g')]

This makes cyphers more readable:

>>> ceasar_cypher("Hi, I'm Bob!".lower(), letter_transformer=vowel_separated_letter_trans)
"jo, o'n cuc!"
>>> ceasar_cypher("jo, o'n cuc!", letter_transformer=invert_mapping(vowel_separated_letter_trans))
"hi, i'm bob!"

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

codify-0.0.8.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

codify-0.0.8-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file codify-0.0.8.tar.gz.

File metadata

  • Download URL: codify-0.0.8.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for codify-0.0.8.tar.gz
Algorithm Hash digest
SHA256 99209214556c58c3a9a7ed10ddfcd08e09f35c81a34d9c1e802fd7f1f7d0dedf
MD5 086a2e825cf6adcfe5516124a109ba6c
BLAKE2b-256 e2ef04f96aed521add679f625c7fe070b885582cafcdfa9968a7fc746f73486d

See more details on using hashes here.

File details

Details for the file codify-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: codify-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for codify-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 3ad2a1b14e8765faa54348356b77de2a413f7209c4d4d16924f0359b1ed41816
MD5 de1efd6e04703bf65a84a001728a570f
BLAKE2b-256 b8d7a17775e66991046d8123f9ebd626af0f963ba884e3a8d9212aaa5abb3243

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