- Notifications
You must be signed in to change notification settings - Fork1
Pack/Unpack 7-bit ASCII text through bit rotation.
License
NotificationsYou must be signed in to change notification settings
pete4abw/bitpacker
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
ASCII Bit Packer/Unpacker=========================7-bit ASCII will be packed into a array of 7 bit bytesbase64 encoding of output string.There are two programs:1. bptest, which provides detailed proof of packing and unpacking strings2. bitp, which is a standalone program to pack and unpackbptest takes one argument: string to pack or unpackbitp takes 2 arguments. p or u to pack or unpack, and a stringString to unpack must be a base64 encoded stringbitp p passwordbitp u base64 encoded bit-packed passwordExample:$ ./bitp p passwordBase64 encoding of password is 4YefPvv5ZA==$ ./bitp u 4YefPvv5ZA==base64 Decoded packed password is: passwordCAUTION: This is not a secure system, merely a way to obscurepasswords.Make and Run============Makefile will compile a shared library libbitpacker.so.Makefile will link the libbitpacker.so into sample programs, bptest and bitp.The libbitpacker.so file can be used by other programs.$ make$ ./bptest "string to pack"$ ./bitp p|u "string to pack/unpack"bptest will also output a file called test.pack which will hold bitpackedoutput.To remove compiled files========================$ make cleanDISCUSSION==========For each byte, shift left and then move bit 6 or more from next byteat each byte, move one more bit to above.7 6 5 4 3 2 1 0===============0 1 1 1 1 1 1 10 2 2 2 2 2 2 2becomes1 1 1 1 1 1 1 2 -> bit 6 from byte 22 2 2 2 2 2 3 3 -> bit 6 and 5 from byte 33 3 3 3 3 4 4 4 -> bit 6, 5, and 4 from byte 4...6 6 7 7 7 7 7 7 -> bit 6, 5...1 from byte 7 7 8 8 8 8 8 8 8 -> bit 0 from byte 7 and bits 6..0 from byte 8so that 8 7-bit bytes becomes 7 8-bit bytes.Output may be unreadable and unprintableso base64 encoding can be usedUncompress works the opposite.Strip 1-6 bits and save from bitpacked byteShift remaining bits over and paste saved bits7 6 5 4 3 2 1 0===============1 1 1 1 1 1 1 2 -> save byte 1 bit 0 for byte 2 which is bit 60 1 1 1 1 1 1 1 -> restore byte 1 by shifting right2 2 2 2 2 2 3 3 -> save bits 0 and 1 for byte 3 which will be bits 5 and 6 ! 2 2 2 2 2 2 -> shift over byte 2 and paste saved bit 60 2 -> to complete byte 23 3 3 3 3 4 4 4 -> save bits 0-2 for byte 4 ! ! 3 3 3 3 3 -> shift over byte 3 and paste saved bits 5 and 6...6 6 7 7 7 7 7 7 -> save bits 0-5 for byte 7 ! ! ! ! ! 6 6 -> paste saved bits for byte 67 8 8 8 8 8 8 8 -> byte 7 contains an unshifted byte 8. Save it. It also has bit 0 for byte 7 in bit 7 ! ! ! ! ! ! 7 -> paste saved bits for byte 7byte 8 is unpacked.so that 7 8-bit bytes becomes 8 7-bit bytes.this works for any number of bytes but will only save byte spaceif 8 or more bytes are packed. While not encryption by any standard, it will obscure data stored because ofthe bit shifting. Base64 encoding can further obscure the original password.Functions---------unsigned char * abitpack( const unsigned char * input)// Pack an array of bytesunsigned char * abitunpack( const unsigned char * input)// Unpack an array of bytesBoth functions return a pointer to packed/unpacked byte stream.If input is NULL or 0 bytes long, NULL is returned and bperr is set.If any byte to be packed is 8 bits, NULL is returned and bperr is set.If any other error occurs, NULL is returned and bperr is set.Globals-------int bperr;/* global error */char *bperrstr[]/* global error strings */#defines--------#define BPEOK 0/* all OK */#define BPENOIN 1/* No input provided */#define BPE8BIT 2/* 8 bit ASCII detected */#define BPENOOUT 3/* this is very bad! */Peter HymanJanuary 2022Updated November 2022pete@peterhyman.com