Package: ordinary
OrdinaryEncoding tools for a largely compatible encryption system based on
the interpolation of character and ordinal values.This library was designed for reverse compatible encryption of characters,
meaning you can encrypt or shelter information using this encoder.Ordinary gets it's name from "ordinal", the name given to the numeric equivalent
of a single character. In Ordinary, ordinals are joined together with a hyphen delimeter to
generate numeric strings otherwise referred to as "Ordinary strings".Methodsencode()Use the encode method to encode standard text into ordinary.encode("Hello world!")>>>72-101-108-108-111-32-119-111-114-108-100-33For pretty formatting, encode may take thecutoffkwarg,
which specifies the number of ordinal files per line. This
is handy when writing to files. It defaults to None, meaning
it will just remain a continuous line. This is fine for shorter encodings.encode("Hello world!",cutoff=5)>>>72-101-108-108-11132-119-111-114-108100-33decode()The reverse ofencode(). Self-explanatory, really.decode("72-101-108-108-111-32-119-111-114-108-100-33")>>>"Hello world!"parse()Parses the given Ordinary to make sure that it is valid.
This function is always used bydecode(). If there is a syntactical
error with the provided Ordinary, OrdinalError will be raised. Otherwise,
nothing will be returned.parse("72-101-108-108-111-32-119-111-114-108-100-33")>>>Noneparse("72-101-108-108-111-32-AAAAAA-111-114-108-100-33")>>>OrdinalError:value'AAAAAA'atposition6isnotadigitsafeparse()Implementsparse(), but returns bool instead of raising, or returning
None. This may be more useful if you're not wanting to raise exceptions
in your program.safeparse("72-101-108-108-111-32-119-111-114-108-100-33")>>>Truesafeparse("72-101-BOO-108-111-32-119-111-114-108-100-33")>>>Falseset_delimiter()Sets the module's delimiter to use when encoding and decoding. The delimiter
must meet the following criteria:Must be a stringMust be a single characterMust not be a digitYou can pass no argument to this function to reset it to the standard (-).set_delimiter("C")>>>Noneencode("Hello world!")>>>"72C101C108C108C111C32C119C111C114C108C100C33"set_delimiter()encode("Hello world!")>>>"72-101-108-108-111-32-119-111-114-108-100-33"get_delimiter()Gets the modules current delimiter.get_delimiter()>>>"-"set_delimiter("C")get_delimiter()>>>"C"temporary_delimiter()This function is to be used as a context manager. It sets the delimiter whilst
the context manager is open.withtemporary_delimiter("C"):encode("Hello world!")>>>"72C101C108C108C111C32C119C111C114C108C100C33"encode("Hello world!")>>>"72-101-108-108-111-32-119-111-114-108-100-33"You can also use theafterkwarg, used to define the delimiter that is set
once the context manager has exited. It defaults to None, meaning it will remember
the previously set delimiter and will instead set it to such delimiter.get_delimiter()>>>"-"withtemporary_delimiter("C",after="D"):...get_delimiter()>>>"D"withtemporary_delimiter("C"):...get_delimiter()>>>"D"load()Loads text from a file and converts, returning a string.fpis a file-like object to extract from.modemust be 'd' or 'e', 'e' standing for encode, 'd' standing for encode. These
modes decide whether encode() or decode() is used on the string that is returned.When using the mode 'e', add 'cutoff' as a keyword argument to be parsed into the
encode function.Here's an example where loading the text would automatically encode:withopen("file","r")asfp:load(fp,mode="e")Same for decoding, just replace the"e"with"d".dump()Convert and write ordinary/text to a file-like object (.write()).This function works likeload(), but there's also a positional argumenttextwhich comes first, which is the text to write to the file. This argument
comes first.withopen("file","r")asfp:dump("Hello world!",fp,mode="e")The above example would write72-101-108-108-111-32-119-111-114-108-100-33to the file object.InstallationInstall using the recommended installer, Pip.pipinstallordinary