#include <stdio.h>
#include <stdlib.h>
int coords[2];
unsigned char translation_1[64] = { 0x00, 0x71, 0x02, 0x73, 0x04, 0x75, 0x06, 0x77,
0x10, 0x61, 0x12, 0x63, 0x14, 0x65, 0x16, 0x67,
0x20, 0x51, 0x22, 0x53, 0x24, 0x55, 0x26, 0x57,
0x30, 0x41, 0x32, 0x43, 0x34, 0x45, 0x36, 0x47,
0x40, 0x31, 0x42, 0x33, 0x44, 0x35, 0x46, 0x37,
0x50, 0x21, 0x52, 0x23, 0x54, 0x25, 0x56, 0x27,
0x60, 0x11, 0x62, 0x13, 0x64, 0x15, 0x66, 0x17,
0x70, 0x01, 0x72, 0x03, 0x74, 0x05, 0x76, 0x07};
unsigned char translation_2[16] = { 0x9, 0xf, 0x3, 0x5, 0x8, 0x2, 0xb, 0xa,
0x1, 0x7, 0x4, 0x0, 0x6, 0xe, 0xc, 0xd};
unsigned char translation_3[32] = { 0x1f, 0x17, 0x09, 0x0a, 0x0b, 0x00, 0x10, 0x18,
0x1e, 0x16, 0x08, 0x0f, 0x0c, 0x01, 0x11, 0x19,
0x1d, 0x15, 0x07, 0x0e, 0x0d, 0x02, 0x12, 0x1a,
0x1c, 0x14, 0x06, 0x05, 0x04, 0x03, 0x13, 0x1b};
unsigned char c_output[32] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345";
void do_xlate_step_one(unsigned char *output, unsigned char *input) {
int key_bit,shift;
unsigned char mask,byte, bit;
for(key_bit = 0; key_bit < 8; key_bit++)
output[key_bit] = 0;
for(key_bit = 0; key_bit < 64; key_bit++) {
shift = (translation_1[key_bit] & 0xf0) >> 4;
mask = 0x01 << shift;
byte = (translation_1[key_bit] & 0x0f);
bit = (input[byte] & mask) ? 1 : 0;
output[key_bit/8] = (output[key_bit/8] << 1) | bit;
}
}
void do_xlate_step_two(unsigned char *output, unsigned char *input) {
unsigned char nibble_a, nibble_b;
int _i;
for(_i = 0; _i < 8; _i++) {
nibble_a = input[_i] & 0x0f;
nibble_b = (input[_i] & 0xf0)>>4;
output[2*_i] = c_output[translation_3[translation_2[nibble_a]]];
output[2*_i+1] = c_output[translation_3[2*translation_2[nibble_b]]];
}
}
int main(int argc, char **argv) {
unsigned char output_step1[0x8], output_step2[17];
if(argc < 3) {
printf("%s <latitutde in decimal degrees as integer> <longitude in decimal degrees as integer>\n",argv[0]);
return -1;
}
output_step2[16] = 0;
coords[0] = atoi(argv[1]);
coords[1] = atoi(argv[2]);
do_xlate_step_one((unsigned char *)output_step1, (unsigned char *)coords);
do_xlate_step_two((unsigned char *)output_step2, (unsigned char *)output_step1);
printf("output: %s \n",output_step2);
coords[0] = 0; coords[1] = 0;
return 0;
}
|
|