Converts text into a numbers and back again.
Project description
Introduction
text2numb is a simple python module for converting text to numbers and back again. It can be used for cryptography, compression or anything else that you can think of.
Basic Tutorial
In order to convert text into numbers, you have to call the text2numb(...)
function. An example is shown below:
>>> import text2numb
>>> num = text2numb.text2numb('Hello, world!')
>>> num
5735816763073854953388147237921
In order to convert this back to plain text, all we need to do is call the numb2text(...)
function.
>>> txt = text2numb.numb2text(num)
>>> txt
Hello, world!
The Setup Function
Every time text2numb is imported, a function called setup(...)
is run. This function sets the int_max_str_size
using the sys function sys.set_int_max_str_size
. It is important that this is called, otherwise errors may occour when trying to convert large amounts of data. However, if for whatever reason you need to change this back to the origional value, you can by using
text2numb.setup(text2numb.max_before_setup)
Backend Workings ⚙️
The code behind text2numb uses the base64 module base-changing functions in order to convert text to numbers. Text is encoded using base64's implementation of base 16, then decoded using functions defined within the module. The result is a number! And by reversing the process, this module can convert numbers back to text.
If you want to convert a number into any base, you can use the _int2base(...)
function. An example is shown below:
>>> text2numb._int2base(14, 9)
'15'
In order to convert this back, you can use:
>>> int('15', 9)
14
In addition to _int2base(...)
, there are two other backend functions - _enc_num(...)
and _dec_num(...)
. These functions are called by text2numb(...)
and numb2text(...)
, and serve as the actual computing functions. If for whatever reason you want to call them directly, they take the same arguments as text2numb(...)
and numb2text(...)
("string" for _enc_num(...)
and "integer" for _dec_num(...)
.
Credits
The credits for the function "_int2base" go to:
Alex Huszagh & Alex Martelli on StackOverflow.com
Their StackOverflow awnser (and the question) can be found here:
https://stackoverflow.com/questions/2267362/how-to-convert-an-integer-to-a-string-in-any-base?r=SearchResults&s=1%7C235.2771
The author of this python module did not ask the origional question.
The credits for the rest of the code go to:
Pigeon Nation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file text2numb-1.1.2.tar.gz
.
File metadata
- Download URL: text2numb-1.1.2.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7dce1d2bb1df41ea60e39f6675b388980975e938cd84124251ce211d106f183c |
|
MD5 | 46c5f5d330c610d6e88f728b7ff32f8c |
|
BLAKE2b-256 | 1c8ab9cf92e166642aad0b5f0467981c4b2e8d9c6465c9c17a4fe536da2d1c51 |
File details
Details for the file text2numb-1.1.2-py3-none-any.whl
.
File metadata
- Download URL: text2numb-1.1.2-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 907dc1ed77e48d63c32bc4d8777265548fd870778d17c5d83d85da1bf848caa1 |
|
MD5 | 2df4405598912af2e358f345e0032ea8 |
|
BLAKE2b-256 | 65217bd93478da934029e3a2f8008157fb8b3e6d8bce0b01c481106490fd5e4c |