Skip to content

noware-sys/bitenc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Converter from a 4-bit hex string representation to a 5-bit base32 or a 6-bit base64 string representation. It can also convert to lower bases, such as 2-binary.


Rationale:
----------
I had found myself wanting to have a shorter string representation of the sha256 or sha512 sums; basenc (base32 or base64[url]) was not really what I wanted, since they produce a longer string.


Command Argument Usage:
-----------------------
Basically (--help/--?):
$ bitenc [--help] [--?] [--HELP] [--bits=5] 
[--charset=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-] [--] [str [...]];
Technically (--HELP):
$ bitenc [[-[-]](h[elp]|?)] [[-[-]]H[ELP]] [[-[-]]b[it[s]]=<1-6>[5]] [[-[-]]c[har[set]]=[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-]] [--] [str<a-zA-Z0-9> [...]];

--bits [optional] [default=5]:
	number of grouping bits/exponent for the base (2):
		1 for a 1-bit, 2^1=2-base binary representation;
		2 for a 2-bit, 2^2=4-base representation;
		3 for a 3-bit, 2^3=8-base representation;
		4 for no net change from 4-bit, 2^4=16-base hexadecimal representation;
		5 for a 5-bit, 2^5=32-base base32 representation (same-case out-charset);
		6 for a 6-bit, 2^6=64-base base64 representation (mixed out-charset case + [_-]);
		any other input would be invalid.
str [optional] [default=<none>]:
	the input string:
		It should contain only the characters [a-zA-Z0-9].
		Without any input string, success/0 is still returned.
--charset [optional] [default='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-']
	The character set, which characters are taken from, for forming the output string.
	This could provide useful if one desires to change the default character set, for example:
		Changing '-' to '+' and '_' to '.':
		$ bitenc -b=6 -c='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.+' abc123...;
		
		Changing the order (this would toggle the letter case of the result):
		$ bitenc -b=6 -c='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-' abc123...;
		
		Changing the order (this would toggle the letter case of the input string):
		$ bitenc -b=4 -c='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-' abc123...;
		
		Testing for proper functionality of the program (this should give back the same input):
		$ bitenc -b=4 [-c='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-'] abc123...;
	
	Only the needed number of characters are taken from this character set, depending on the requested bits/base:
		For bits==4/base==16:
			Number of used characters from the beginning: 16.
			For the default value of the charset, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-', only these first ones would be used: '0123456789abcdef', regardless of any other subsequent ones which may be present.
		For bits==5/base==32:
			Number of used characters from the beginning: 32.
			For the default value of the charset, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-', only these first ones would be used: '0123456789abcdefghijklmnopqrstuv', regardless of any other subsequent ones which may be present.
		For bits==6/base==64:
			Number of used characters from the beginning: 64.
			For the default value of the charset, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-', only these first ones would be used (all of them): '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-', regardless of any other subsequent ones which may be present.

Dependency:
-----------
- BASH (interpreter of this script);
- Perl (in path of this script; called on line 184).

Note:
-----
The characters '_' and '-' were arbitrarily chosen, as they seemed the most neutral ones to use in miscellaneous contexts (file systems, urls), compared to other ones, such as [ .,;:~+=!@#$%^&|], and especially [`/\].

No additional error checking is performed: for example, if the bits argument is not an integer, then undetermined program behaviour could occur.

The error message for an invalid/unknown character in the input string starts counting them from substring position 0 (aka the first character would be #0).


Issue/Bug:
----------
Please report a bug/problem by opening an issue here.


Comment/Suggestion/Other:
-------------------------
To make a comment or a suggestion, or simply to start a conversation, see the discussions here.

Releases

No releases published

Packages

No packages published

Languages