
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "lprintf.h"
#include "lib.h"
#include "key.h"


// Provide moderately obfuscated authentication cookies that have no visible obvious repeating pattern
// Written for use in surgeweb... used elsewhere too.
char *string_hide(char *txt, char *bf, int bfsz, int norand)
{
	char bf2[BFSZ];
	int seed,xseed;

	if(norand)
		seed=lib_strlen(txt)%100+100;
	else
		seed=myrand()%100+100;
//	seed=145;
	xseed=10+seed%25;
	lib_hide("surgeweb",txt,xseed,bf2);
	lprintf(bf,bfsz,"%d%s",seed,bf2);
	return bf;
}

char *string_unhide(char *txt, char *bf, int bfsz, int norand)
{
	char bf2[BFSZ];
	int xseed;

	ncpy(bf2,txt,3);
	xseed=10+atoi(bf2)%25;
	lib_unhide("surgeweb",txt+3,xseed,bf);	
	return bf;
}
