![]() |
BluePoint Encryption
is a simple, secure, state of the art block encryption algorithm. It
requires minimal processing power and has a low memory footprint. The
algorithm produces an even bit distribution, even when its fed with
small data or homogenus content. This makes it highly resilient against
crypt analysis, and an ideal candidate where safe, secure and
customized encryption is needed. The BluePoint Encryption is available
in source code format in the following languages: 'C', PHP, Perl,
JavaScript, ... All the source code ports are cypher text compatible,
content encoded with one port, can be decoded in other ports.
|
| Bluepoint
Encryption Download In it's simplest form, one can cut and paste the code from below. Alternatively, the zipped up archive of the latest version, including all documentation, web content and sorces in all languages are avalible here. Make sure you read the License terms. //# ------------------------------------------------------------------------- //# Bluepoint encryption routines. //# //# How it works: //# //# Strings are walked chr by char with the loop: //# { //# $aa = ord(substr($_[0], $loop, 1)); //# do something with $aa //# substr($_[0], $loop, 1) = pack("c", $aa); //# } //# //# Flow: //# generate vector //# generate pass //# walk forward with password cycling loop //# walk backwards with feedback encryption //# walk forward with feedback encryption //# //# The process guarantees that a single bit change in the original text //# will change every byte in the resulting block. //# //# The bit propagation is such a high quality, that it beats current //# industrial strength encryptions. //# //# Please see bit distribution study. //# //# ------------------------------------------------------------------------- #include "stdio.h" #include "string.h" #include "bluepoint.h" #define ROTATE_LONG_RIGHT(x, n) (((x) >> (n)) | ((x) << (32 - (n)))) static void encrypt(char *str, int slen, char *pass, int plen); static void decrypt(char *str, int slen, char *pass, int plen); static void prep_pass(char *pass, int plen, char *newpass); //# ------------------------------------------------------------------------- //# These vars can be set to make a custom encryption: char vector[] = "crypt"; //# influence encryption algorythm int passlim = 32; //# maximum key length (bytes) char forward = 0x55; //# Constant propagated on forward pass char backward = 0x5a; //# Constant propagated on backward pass char addend = 17; //# Constant used adding to encrypted values //# ------------------------------------------------------------------------- //# These vars can be set show op details int verbose = 0; //# Specify this to show working details int functrace = 0; //# Specify this to show function args //# ------------------------------------------------------------------------- //# Use: encrypt($str, $password); void bluepoint_encrypt(char *buff, int blen, char *pass, int plen) { char newpass[2 * passlim]; if(plen == 0 || blen == 0) { return; } // if(functrace) // { // printf("bluepoint_encrypt\nbuff=%s\n", bluepoint_dumphex(buff, blen)); // printf("pass=%s\n", bluepoint_dumphex(pass, plen) ); // } prep_pass(pass, plen, newpass); encrypt(buff, blen, newpass, passlim); } //# ------------------------------------------------------------------------- //# Use: bluepoint_decrypt($str, $password); void bluepoint_decrypt(char *buff, int blen, char *pass, int plen) { char newpass[2 * passlim]; if(plen == 0 || blen == 0) { return; } //if(functrace) // { // printf("encrypt()\nbuff=%s\n", bluepoint_dumphex(buff, blen)); // printf("pass=%s\n", bluepoint_dumphex(pass, plen) ); // } prep_pass(pass, plen, newpass); decrypt(buff, blen, newpass, passlim); } /////////////////////////////////////////////////////////////////////////// // Prepare pass void prep_pass(char *pass, int plen, char *newpass) { int loop; char vec2[passlim]; int len = strlen(vector); strcpy(vec2, vector); newpass[0] = 0; for(loop = 0; loop < passlim / plen + 1; loop++) { strcat(newpass, pass); strcat(newpass, "_"); } newpass[passlim] = 0; //printf("newpass: %s\n", newpass); encrypt(vec2,len, vector, len); //#print "e VEC: "; dumpdec($vec2); print "\n"; encrypt(newpass, passlim, vec2, len); //#print "e PAS2: "; dumpdec($passwd); print "\n"; } //# ------------------------------------------------------------------------- //# Hash: //# use: hashvalue = hash($str) //# //# Implementing the following 'C' code //# //# define ROTATE_LONG_RIGHT(x, n) (((x) >> (n)) | ((x) << (32 - (n)))) //# ret_val ^= (unsigned long)*name; //# ret_val = ROTATE_LONG_RIGHT(ret_val, 10); /* rotate right */sub hash //# long bluepoint_hash(char *buff, int blen) { long sum = 0; int loop; char aa, aa2, aa3; for (loop = 0; loop < blen; loop++) { printf("%c ", buff[loop]); sum ^= buff[loop]; //ROTATE_LONG_RIGHT(sum, 10); /* rotate right */ } return sum; } #if 0 //# ------------------------------------------------------------------------- //# Crypt and hash: //# use: crypthash = chash($str, "pass") sub chash { my($str, $sum); $str = encrypt($_[0], $_[1]); $sum = hash($str); return($sum); } //# ------------------------------------------------------------------------- //# Make checksum //# use: sum = chksum($str) sub chksum { my($len, $aa, $sum, $loop); $len = length($_[0]); for ($loop = 0; $loop < $len; $loop++) { $aa = ord(substr($_[0], $loop, 1)); $sum = $sum + $aa; } return $sum; } #endif //# ------------------------------------------------------------------------- //# The following routines are internal to this module: void encrypt(char *str, int slen, char *pass, int plen) { int loop, loop2 = 0; unsigned char aa, bb;; //printf( "encrypt str='%s' len=%d pass='%s' plen=%d\n", // str, slen, pass, plen); //# Pass loop (encrypt) for (loop = 0; loop < slen; loop++) { aa = str[loop]; aa = aa ^ pass[loop2]; loop2++; if(loop2 >= plen) {loop2 = 0;} //#wrap over str[loop] = aa; } //# Backward loop (encrypt) bb = 0; for (loop = slen-1; loop >= 0; loop--) { aa = str[loop]; aa = ((aa ^ backward) + addend) + bb; bb = aa; str[loop] = aa; } //# Forward loop (encrypt) bb = 0; for (loop = 0; loop < slen; loop++) { aa = str[loop]; aa = ((aa ^ forward) + addend) + bb; bb = aa; str[loop] = aa; } } //# ------------------------------------------------------------------------- //# Internal to this module: void decrypt(char *str, int slen, char *pass, int plen) { int loop, loop2 = 0; unsigned char aa, bb, cc; //printf( "decrypt(inp) str=%s len=%d pass=%s plen=%d\n", // str, slen, pass, plen); //# Forward loop (decrypt) cc = 0; for (loop = 0; loop < slen; loop++) { bb = cc; aa = str[loop]; cc = aa; aa = ((aa - bb) - addend) ^ forward; str[loop] = aa; } //# Backward loop (decrypt) cc = 0; for (loop = slen-1; loop >= 0; loop--) { bb = cc; aa = str[loop]; cc = aa; aa = ((aa - bb) - addend) ^ backward; str[loop] = aa; } //# Pass loop (decrypt) for (loop = 0; loop < slen; loop++) { aa = str[loop]; aa = aa ^ pass[loop2]; loop2++; if(loop2 >= plen) {loop2 = 0;} //#wrap over str[loop] = aa; } //#print "pl_decrypt(out) out2=$out2\n"; } //# ------------------------------------------------------------------------- //# Use: bluepoint_dumphex($str) char buff[256]; char *bluepoint_dumphex(char *str, int len) { buff[0] = 0; int loop = 0, pos = 0; for (loop = 0; loop < len; loop++) { pos += sprintf(buff + pos, "-%02x", ( unsigned char)str[loop]); if(pos >= sizeof(buff) - 8) break; } return(buff); } |
| Site
Copyright by Peter Glen, (c) 2007 |