static unsigned long extract
__ARGS((char *s
,int start
,int length
));
static void standard
__ARGS((char *word
));
static void insert
__ARGS((char *s
, int x
, int start
, int length
));
static int wsrch
__ARGS((char *w
,int low
,int high
));
/* Dictionary for integer-word translations */
/* Encode 8 bytes in 'c' as a string of English words.
* Returns a pointer to a static buffer
char cp
[9]; /* add in room for the parity 2 bits*/
for(p
= 0,i
= 0; i
< 64;i
+= 2)
strncat(engout
,&Wp
[extract(cp
, 0,11)][0],4);
strncat(engout
,&Wp
[extract(cp
,11,11)][0],4);
strncat(engout
,&Wp
[extract(cp
,22,11)][0],4);
strncat(engout
,&Wp
[extract(cp
,33,11)][0],4);
strncat(engout
,&Wp
[extract(cp
,44,11)][0],4);
strncat(engout
,&Wp
[extract(cp
,55,11)][0],4);
printf("engout is %s\n\r",engout
);
/* convert English to binary
* returns 1 OK - all good words and parity is OK
* 0 word not in data base
* -1 badly formed in put ie > 4 char word
* -2 words OK but parity is wrong
strncpy(input
,e
,sizeof(input
));
for(i
=0,p
=0;i
<6;i
++,p
+=11){
if((word
= strtok(i
== 0 ? input
: NULL
," ")) == NULL
)
if( (v
= wsrch(word
,low
,high
)) < 0 )
/* now check the parity of what we got */
for(p
= 0, i
= 0; i
< 64; i
+=2)
if( (p
& 3) != extract(b
, 64,2) )
/* Display 8 bytes as a series of 16-bit hex digits */
sprintf(out
,"%02X%02X %02X%02X %02X%02X %02X%02X",
s
[0] & 0xff,s
[1] & 0xff,s
[2] & 0xff,
s
[3] & 0xff,s
[4] & 0xff,s
[5] & 0xff,
s
[6] & 0xff,s
[7] & 0xff);
/* Encode 8 bytes in 'cp' as stream of ascii letters.
* Provided as a possible alternative to btoe()
/* code out put by characters 6 bits each added to 0x21 (!)*/
/* last one is only 4 bits not 6*/
out
[i
] = '!'+ extract(cp
,6*i
,i
>= 10 ? 4:6);
/* Internal subroutines for word encoding/decoding */
/* Dictionary binary search */
if((j
= strncmp(w
,Wp
[i
],4)) == 0)
/* Avoid effects of integer truncation in /2 */
if(strncmp(w
,Wp
[high
],4) == 0)
return -1; /* I don't *think* this can happen...*/
high
= i
; /* Search lower half */
low
= i
; /* Search upper half */
insert(s
, x
, start
, length
)
assert(start
+length
<= 66);
shift
= ((8 -(( start
+ length
) % 8))%8);
} else if(shift
+length
> 8){
/* Extract 'length' bits from the char array 's' starting with bit 'start' */
extract(s
, start
, length
)
assert(start
+length
<= 66);
x
= ((long)(cl
<<8 | cc
) <<8 | cr
) ;
x
= x
>> (24 - (length
+ (start
%8)));
x
=( x
& (0xffff >> (16-length
) ) );