Browse Source

Convert code to C

master
Jacob Still 1 year ago
parent
commit
617263e4c7
Signed by: jcstill GPG Key ID: 9FA6C3681688446C
  1. 259
      Makefile
  2. 3
      README.md
  3. 236
      dbpbe.c
  4. 266
      dbpbe.h
  5. 226
      main.c

259
Makefile

@ -1,41 +1,262 @@
# Compiler Specific:
COMP=g++
COMP=gcc
CFLAG=-c
WFLAG=-Wall
OFLAG=-o
testnum=0
# Program Specific:
SOURCES= main.cpp
SOURCES= main.c \
dbpbe.c
OBJECTS=$(SOURCES:.cpp=.o)
HEADERS=$(SOURCES:.cpp=.h)
OBJECTS=$(SOURCES:.c=.o)
HEADERS=$(SOURCES:.c=.h)
EXECUTABLE=DBPBE
# Start of Make:
Start: clean $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(COMP) $(OBJECTS) $(OFLAG) $@ $(WFLAG)
$(COMP) $(OBJECTS) -lm $(OFLAG) $@ $(WFLAG)
.cpp.o:
$(COMP) -D mode=$(testnum) $(CFLAG) $< $(OFLAG) $@ $(WFLAG)
.c.o:
$(COMP) -D MODE=$(testnum) $(CFLAG) $< $(OFLAG) $@ $(WFLAG)
# Cleanup Routines:
clean:
rm -f $(OBJECTS) $(EXECUTABLE)
clean-o:
rm -f $(OBJECTS)
clean-b:
rm -f $(EXECUTABLE)
clean-tar:
rm -f $(EXECUTABLE).tar
# # Packaging
# tar:
# tar -cf $(EXECUTABLE).tar *.c *.h
show-tar:
tar -tvf $(EXECUTABLE).tar
tar:
tar -cf $(EXECUTABLE).tar *.cpp *.h

3
README.md

@ -14,13 +14,12 @@ there are a bunch of testing things that i have built into the main cpp file:
- mode 03 = testing for conversions
- mode 04 = testing for conversions 2.0
- mode 05 = testing string inputs
- mode 06 = testing string inputs into list
- //mode 06 = testing string inputs into list
- mode 07 = testing key generation based on passphrase
- mode 08 = testing key generation based on rand
- mode 09 = testing converting char to distances
- mode 10 = testing converting string to distances
- mode 11 = testing converting to and from distances with chars
- mode 12 = testing converting to and from distances with strings
to compile:

236
dbpbe.c

@ -0,0 +1,236 @@
// dbpbe.c is part of the DBPBE project
// Copyright (C) 2020 Jacob Still jacobcstill@gmail.com
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "dbpbe.h"
uint8_t converttodata(struct coordinate point){
return (uint8_t)(truncl(fabsl(point.y))/16838387);
}
void converttopoint(struct coordinate *point, uint8_t input){
point->x = (long long)((unsigned int)(input) * (unsigned int)(16785407) * 5) % 4294967295; // !TODO: Issue #1,7 this modulo may be interfereing with converting back in converttopoint()
point->y = (long long)(unsigned int)(input) * (unsigned int)(16838387);
bool positivex = (bool)(((unsigned int)(2097593) % (((unsigned int)(input) % (unsigned int)(43)) + (unsigned int)(1)) * (unsigned int)(input) * (unsigned int)(16785407)) % 2);
bool positivey = (bool)(((unsigned int)(5020783) % (((unsigned int)(input) % (unsigned int)(37)) + (unsigned int)(1)) * (unsigned int)(input) * (unsigned int)(16838387)) % 2);
long double postx = (unsigned int)(2097593) % (((unsigned int)(input) % (unsigned int)(43)) + (unsigned int)(1));
long double posty = (unsigned int)(5020783) % (((unsigned int)(input) % (unsigned int)(37)) + (unsigned int)(1));
int tmp = 0;
unsigned int no = postx;
while(no>0){
no=no/10;
tmp++;
}
no = pow(10, tmp);
postx /= no;
point->x += postx;
if(!positivex){
point->x *= -1;
}
tmp = 0;
no = posty;
while(no>0){
no=no/10;
tmp++;
}
no = pow(10, tmp);
posty /= no;
point->y += posty;
if(!positivey){
point->y *= -1;
}
}
void genkeypointrnd(struct coordinate *point){
bool positivex = (bool)(rand()%2);
unsigned int b = 0;
for(int i=0;i<32;++i){
unsigned int s = rand()%2;
b = b << 1;
b = b | s;
}
unsigned int c = 0;
for(int i=0;i<32;++i){
unsigned int s = rand()%2;
c = c << 1;
c = c | s;
}
bool positivey = (bool)(rand()%2);
unsigned int e = 0;
for(int i=0;i<32;++i){
unsigned int s = rand()%2;
e = e << 1;
e = e | s;
}
unsigned int f = 0;
for(int i=0;i<32;++i){
unsigned int s = rand()%2;
f = f << 1;
f = f | s;
}
point->x = (long double)(b);
point->y = (long double)(e);
long double postx = (long double)(c);
long double posty = (long double)(f);
int tmp = 0;
unsigned int no = postx;
while(no>0){
no=no/10;
tmp++;
}
no = pow(10, tmp);
postx /= no;
point->x += postx;
if(!positivex){
point->x *= -1;
}
tmp = 0;
no = posty;
while(no>0){
no=no/10;
tmp++;
}
no = pow(10, tmp);
posty /= no;
point->y += posty;
if(!positivey){
point->y *= -1;
}
}
void genkeypoint(struct coordinate *point, const char input[], int size){
char hash[size+1];
char KEY;
for(int i=0; i<size; ++i){
hash[i]='\0';
KEY = (input[i] * input[i] / 2) % 255;
hash[i] = KEY ^ (input[i] ^ KEY/2) % 255;
}
hash[size] = '\0';
for(int w=0; w<size; ++w){
for(int i=0; i<size; ++i){
if(i > 0 && i < size){
hash[i] = ((hash[i] * 68718952447) ^ hash[i-1]) % 255;
}else if(i == size){
hash[i] = ((hash[i] * 87178291199) ^ hash[i]) % 255;
}else{
hash[i] = (hash[i] ^ 181081) % 255;
}
}
}
unsigned int convert = 0;
for(int i=0; i<size; i++){
convert += (unsigned int)((uint8_t)(hash[i]));
convert %= 255;
}
// !IMMEDIATE: Issue #9
// need to fix this as it is the same code as an edge case where a distance is 0 can occur
point->x = (long long)(((unsigned int)(convert) * (unsigned int)(16785407)) * 5) % 4294967295;
bool positivex = (bool)(((unsigned int)(2097593) % (((unsigned int)(convert) % (unsigned int)(43)) + (unsigned int)(1)) * (unsigned int)(convert) * (unsigned int)(16785407)) % 2);
long double postx = (unsigned int)(2097593) % (((unsigned int)(convert) % (unsigned int)(43)) + (unsigned int)(1));
for(int i=0; i<size; i++){
convert *= (unsigned int)((uint8_t)(hash[i]));
convert %= 255;
}
point->y = (long long)((unsigned int)(convert) * (unsigned int)(16838387));
bool positivey = (bool)(((unsigned int)(5020783) % (((unsigned int)(convert) % (unsigned int)(37)) + (unsigned int)(1)) * (unsigned int)(convert) * (unsigned int)(16838387)) % 2);
long double posty = (unsigned int)(5020783) % (((unsigned int)(convert) % (unsigned int)(37)) + (unsigned int)(1));
int tmp = 0;
unsigned int no = postx;
while(no>0){
no=no/10;
tmp++;
}
no = pow(10, tmp);
postx /= no;
point->x += postx;
if(!positivex){
point->x *= -1;
}
tmp = 0;
no = posty;
while(no>0){
no=no/10;
tmp++;
}
no = pow(10, tmp);
posty /= no;
point->y += posty;
if(!positivey){
point->y *= -1;
}
}
long double calcdist(struct coordinate data, struct coordinate key){
return (sqrtl(powl(key.x - data.x, 2) + powl(key.y - data.y, 2)));
}
bool withinPercent(long double first, long double percent, long double second){
long double decimalPercent = percent / 200.0;
long double highRange = second * (1.0 + decimalPercent);
long double lowRange = second * (1.0 - decimalPercent);
return lowRange <= first && first <= highRange;
}
int circle_circle_intersection(long double x0,long double y0,long double r0,long double x1,long double y1,long double r1,long double *xi,long double *yi,long double *xi_prime,long double *yi_prime){
long double a, dx, dy, d, h, rx, ry, x2, y2;
dx = x1 - x0;
dy = y1 - y0;
d = hypot(dx,dy);
long double percent = 0.05;
if(!withinPercent(d,percent,(r0 + r1)) && !withinPercent(d,percent,(r0 - r1))){
if(d > (r0 + r1)){
//ERROR: circles do not intersect
exit(1);
return 1;
}
if(d < fabsl(r0 - r1)){
//ERROR: one circle is contained in the other
exit(2);
return 1;
}
}
a = ((r0*r0) - (r1*r1) + (d*d)) / (2.0 * d);
x2 = x0 + (dx * a/d);
y2 = y0 + (dy * a/d);
h = sqrtl((r0*r0) - (a*a));
rx = -dy * (h/d);
ry = dx * (h/d);
*xi = x2 + rx;
*xi_prime = x2 - rx;
*yi = y2 + ry;
*yi_prime = y2 - ry;
return 0;
}
long double get_single(long double x[6]){
long double tmp = 0;
for(int i=0;i<6;++i){
for(int w=i+1;w<6;++w){
long double difference = fabsl(x[i] - x[w]);
if(difference < 10){
tmp = x[i];
}
}
}
return tmp;
}
struct coordinate calccord(long double dist0, long double dist1, long double dist2, struct coordinate key0, struct coordinate key1, struct coordinate key2){
long double x[6] = {1, 1, 1, 1, 1, 1};
long double y[6] = {1, 1, 1, 1, 1, 1};
circle_circle_intersection(key0.x, key0.y, dist0, key1.x, key1.y, dist1, &x[0], &y[0], &x[1], &y[1]);
circle_circle_intersection(key1.x, key1.y, dist1, key2.x, key2.y, dist2, &x[2], &y[2], &x[3], &y[3]);
circle_circle_intersection(key2.x, key2.y, dist2, key0.x, key0.y, dist0, &x[4], &y[4], &x[5], &y[5]);
long double xchar = get_single(x);
long double ychar = get_single(y);
struct coordinate tmp;
tmp.x = xchar;
tmp.y = ychar;
return tmp;
}

266
dbpbe.h

@ -0,0 +1,266 @@
// dbpbe.h is part of the DBPBE project
// Copyright (C) 2020 Jacob Still jacobcstill@gmail.com
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef __DBPBE_H__
#define __DBPBE_H__
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <stdint.h>
#include <time.h>
/*******************************************************************************
* coordinate -- Struct storing the x and y components of the coordinate *
* *
* NOTE: *
* *
* HISTORY: *
* 07/11/2020 - Created *
* *
******************************************************************************/
struct coordinate{
long double x;
long double y;
};
/*******************************************************************************
* converttodata -- Converts a stored struct coordinate to an 8 bit value *
* *
* NOTE: *
* !TODO: Issue #7 *
* Shouldn't fail - needs to be tested *
* *
* INPUT: struct - coordinate *
* *
* OUTPUT: uint8_t - data that is stored from from converttopoint() *
* *
* HISTORY: *
* 03/06/2020 - Created *
* 06/12/2020 - Updated for use with new converttopoint() function *
* 07/11/2020 - Adjusted for C *
* *
******************************************************************************/
uint8_t converttodata(struct coordinate point);
/*******************************************************************************
* converttopoint -- Converts an 8 bit value to a struct coordinate that is *
* then stored *
* *
* NOTE: *
* !TODO: Issue #6 *
* types still need to be looked at (since using long doubles as coord type)*
* 1 input is multiplied by a prime number: *
* x = (input * 16785407 * 5) % 4294967295 *
* y = input * 16838387 *
* !NOTE: prime numbers were chosen so that any 8 bit number can't multiply *
* to greater than size of long long *
* *
* 2 then weather or not both components of the coordinate are negative is *
* calculated based on input: *
* positivex = (2097593 % ((input % 43) + 1) * input * 16785407) % 2; *
* positivey = (5020783 % ((input % 37) + 1) * input * 16838387) % 2; *
* *
* 3 the data post-decimal is then calculated based on input: *
* postx = 2097593 % ((input % 43) + 1); *
* posty = 5020783 % ((input % 37) + 1); *
* *
* 4 the post-decimal data is then divided by 10 until it is less than 1 then *
* it is added to the respective component the component is then multiplied *
* by -1 if it needs to be negative. *
* *
* INPUT: *
* struct - coordinate *
* input - data to be converted to a struct coordinate *
* *
* OUTPUT: none *
* *
* HISTORY: *
* 03/06/2020 - Created *
* 06/12/2020 - Completely Restructured how this function works *
* 07/11/2020 - Adjusted for C *
* *
******************************************************************************/
void converttopoint(struct coordinate *point, uint8_t input);
/*******************************************************************************
* genkeypointrnd -- Generate key point based on rand() *
* *
* NOTE: *
* Need to call srand(time(NULL)) once at beginning of program *
* !TODO: Add Hash functionality to this as well??? *
* *
* !TODO: Issue #6 *
* fix datatypes completely *
* 1 Each bit of the pre-decimal portion of the coordinate is generated by *
* std::rand() and bit shifted into place *
* !NOTE: keys are 64 bits long (when they are generated) *
* *
* 2 Weather each component of the coordinate is negative is generated by *
* std::rand() *
* *
* 3 The data post-decimal is generated by std::rand() *
* *
* The post-decimal data is divided by 10 until it is less than 1. Then it *
* is added to the respective component of the coordinate. The component is *
* then multiplied by -1 if it needs to be negative. *
* *
* INPUT: struct - coordinate *
* *
* OUTPUT: none *
* *
* HISTORY: *
* 06/12/2020 - Created *
* 07/11/2020 - Adjusted for C *
* *
******************************************************************************/
void genkeypointrnd(struct coordinate *point);
/*******************************************************************************
* genkeypoint -- Generate key point based on user input *
* *
* NOTE: *
* A Hash is generated from the user input and then the same computations *
* are done on it (just with different numbers) *
* *
* INPUT: *
* struct - coordinate *
* input - cstring passphrase passed in *
* size - number of characters in the cstring *
* *
* OUTPUT: none *
* *
* HISTORY: *
* 03/07/2020 - Created *
* 03/09/2020 - Slight modification of interworkings *
* 06/12/2020 - Changed to hash based key generetion *
* 07/11/2020 - Adjusted for C *
* *
******************************************************************************/
void genkeypoint(struct coordinate *point, const char input[], int size);
/*******************************************************************************
* calcdist -- Calculates the distance between two keys *
* *
* NOTE: *
* *
* INPUT: data,key - coordinates to calculate distance from *
* *
* OUTPUT: none *
* *
* HISTORY: *
* 05/08/2020 - Created *
* 06/12/2020 - Simplified function *
* 07/11/2020 - Adjusted for C *
* *
******************************************************************************/
long double calcdist(struct coordinate data, struct coordinate key);
/*******************************************************************************
* withinPercent -- Checks if two numbers are within a percentage of each other*
* *
* NOTE: *
* *
* INPUT: *
* first,second - two numbers to calculate *
* percent - percentage to calculate with - 20% should be passed as 20.0 *
* *
* OUTPUT: bool - if the numbers are within a percentage of each other or not *
* *
* HISTORY: *
* 06/12/2020 - Created *
* 07/11/2020 - Adjusted for C *
* *
******************************************************************************/
bool withinPercent(long double first, long double percent, long double second);
/*******************************************************************************
* circle_circle_intersection -- Calculates the intersection points between *
* two circles *
* *
* NOTE: *
* Based on work by Paul Bourke: *
* http://paulbourke.net/geometry/circlesphere/ *
* Code basically copied from Tim Voght: *
* http://paulbourke.net/geometry/circlesphere/tvoght.c *
* *
* INPUT: respective components of two circles AND pointers to components of *
* intersection points *
* *
* OUTPUT: int - error codes !TODO: remove error codes and make void function *
* *
* HISTORY: *
* 05/08/2020 - Created *
* 06/12/2020 - Fix function returning errors *
* 07/11/2020 - Adjusted for C *
* *
******************************************************************************/
int circle_circle_intersection(long double x0,long double y0,long double r0,long double x1,long double y1,long double r1,long double *xi,long double *yi,long double *xi_prime,long double *yi_prime);
/*******************************************************************************
* get_single -- Returns the coordinate component that occurs the most *
* *
* NOTE: *
* !TODO: Issue #7 *
* Modify code to actually check which one occurs the most *
* *
* INPUT: x - array of components of a coordinate *
* *
* OUTPUT: long double - number that occurs the most in input array *
* *
* HISTORY: *
* 05/08/2020 - Created *
* 07/11/2020 - Adjusted for C *
* *
******************************************************************************/
long double get_single(long double x[6]);
/*******************************************************************************
* calccord -- Returns the coordinate that was converted into distances based *
* on key points *
* *
* NOTE: *
* Each distance has a respective key. ie, dist0 is the distance from key0 *
* *
* INPUT: *
* dist{0-2} - three distance components *
* key{0-2} - three keys *
* *
* OUTPUT: coordinate - the coordinate that is referred to by all the keys and *
* distances *
* *
* HISTORY: *
* 05/08/2020 - Created *
* 06/12/2020 - Simplified code a bit *
* 07/11/2020 - Adjusted for C *
* *
******************************************************************************/
struct coordinate calccord(long double dist0, long double dist1, long double dist2, struct coordinate key0, struct coordinate key1, struct coordinate key2);
#endif

226
main.c

@ -0,0 +1,226 @@
// This file is part of the DBPBE project
// Copyright (C) 2020 Jacob Still jacobcstill@gmail.com
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "dbpbe.h"
#include <stdio.h>
#include <string.h>
#ifndef MODE
#define MODE 0
#endif
char *inputString(FILE* fp){
// yes this is code copied from stackoverflow. no, I dont care, since this whole file is an example.
char *str;
int ch;
size_t size=16, len=0;
str = realloc(NULL, sizeof(char)*size);
if(!str){
return str;
}
while(EOF!=(ch=fgetc(fp))&&ch!='\n'){
str[len++]=ch;
if(len==size){
str = realloc(str, sizeof(char)*(size+=16));
if(!str){
return str;
}
}
}
str[len++]='\0';
return realloc(str, sizeof(char)*len);
}
int main(){
#if MODE <= 0
printf ("nothing to do for mode \"%i\"\n", MODE);
#elif MODE == 1
printf("MODE: %i\n\tTESTING ", MODE);
printf("FOR DATATYPE CASTING\n");
uint8_t unencrypted = (uint8_t)('A');
printf ("uint8_t: %u\n", unencrypted);
printf ("int: %i\n", (int)(unencrypted));
printf ("unsigned int: %u\n", (unsigned int)(unencrypted));
printf ("char: %c\n", (char)(unencrypted));
unsigned int converted = (long long)(((unsigned int)(unencrypted) * (unsigned int)(16785407)) * 5) % 4294967295;
printf("Converted: %u\n", converted);
struct coordinate tmp;
converttopoint(&tmp,unencrypted);
printf("\"%03u\" ", (unsigned int)(unencrypted));
printf("%22.10Lf,%23.10Lf\n", tmp.x, tmp.y);
#elif MODE == 2
printf("MODE: %i\n\tTESTING ", MODE);
printf("FOR DATATYPE CASTING 2.0\n");
for(uint8_t unencrypted=0; unencrypted<255; ++unencrypted){
printf("\"%03u\" ", (unsigned int)(unencrypted));
struct coordinate tmp;
converttopoint(&tmp,unencrypted);
printf("%22.10Lf,%23.10Lf\n", tmp.x, tmp.y);
}
#elif MODE == 3
printf("MODE: %i\n\tTESTING ", MODE);
printf("FOR CONVERSIONS\n");
uint8_t unencrypted = (uint8_t)('Y');
struct coordinate tmp;
converttopoint(&tmp,unencrypted);
printf("Original uint8_t:\t%u\n", unencrypted);
printf("%22.10Lf,%23.10Lf\n", tmp.x, tmp.y);
printf("Converted uint8_t:\t%u\n", converttodata(tmp));
#elif MODE == 4
printf("MODE: %i\n\tTESTING ", MODE);
printf("FOR CONVERSIONS 2.0\n");
for(uint8_t unencrypted=0; unencrypted<255; ++unencrypted){
struct coordinate tmp;
converttopoint(&tmp,unencrypted);
printf("%03u", unencrypted);
printf(" %03u", converttodata(tmp));
printf("\t%22.10Lf,%23.10Lf\n", tmp.x, tmp.y);
}
#elif MODE == 5
printf("MODE: %i\n\tTESTING ", MODE);
printf("STRING INPUTS\n");
printf("enter string to convert to points: ");
char *input;
input = inputString(stdin);
for(unsigned int i=0; i<strlen(input); ++i){
struct coordinate tmp;
converttopoint(&tmp,(uint8_t)(input[i]));
printf("%c", input[i]);
printf("%23.10Lf,%23.10Lf", tmp.x, tmp.y);
printf(" %c\n", converttodata(tmp));
}
free(input);
#elif MODE == 6
printf("MODE: %i\n\tTESTING ", MODE);
printf("STRING INPUTS INTO LIST\n");
printf("Sorry, I dont feel like implementing a linked list...\n");
// My C++ code that i havent bothered to move to C
// list<coordinate> mylist;
// string input;
// cout << "enter string to convert to points: ";
// getline(cin, input);
// cout << "\nPoints:\n";
// for(unsigned int i=0; i<input.length(); ++i){
// struct coordinate tmp;
// tmp.converttopoint((uint8_t)(input[i]));
// cout << fixed << setprecision(10) << setw(23) << right << tmp.getx() << ", " << setw(22) << right << tmp.gety() << '\n';
// mylist.push_back(tmp);
// }
// cout << "\nConverted back:\n";
// while(mylist.size()!=0){
// cout << mylist.front().converttodata();
// mylist.pop_front();
// }
// cout << '\n';
#elif MODE == 7
printf("MODE: %i\n\tTESTING ", MODE);
printf("KEY GENERATION BASED ON PASSPHRASE\n");
srand(time(NULL));
struct coordinate tmp;
printf("enter string to convert to key: ");
char *input;
input = inputString(stdin);
genkeypoint(&tmp, input, strlen(input));
printf("%23.10Lf,%23.10Lf\n", tmp.x, tmp.y);
free(input);
#elif MODE == 8
printf("MODE: %i\n\tTESTING ", MODE);
printf("KEY GENERATION BASED ON RAND\n");
srand(time(NULL));
printf("enter number of keys to generate: ");
unsigned int input;
scanf(" %d",&input);
struct coordinate tmp[input];
for(unsigned int i=0; i<input; ++i){
genkeypointrnd(&tmp[i]);
printf("%23.10Lf,%23.10Lf\n", tmp[i].x, tmp[i].y);
}
#elif MODE == 9
printf("MODE: %i\n\tTESTING ", MODE);
printf("CONVERTING CHAR TO DISTANCES\n");
srand(time(NULL));
uint8_t input;
printf("enter data char: ");
scanf(" %c",&input);
printf("Data:\t");
struct coordinate data;
converttopoint(&data, input);
printf("%23.10Lf,%23.10Lf\n", data.x, data.y);
printf("Key1:\t");
struct coordinate key1;
genkeypointrnd(&key1);
printf("%23.10Lf,%23.10Lf\n", key1.x, key1.y);
long double dist = calcdist(data, key1);
printf("Dist:\t%23.10Lf\n", dist);
#elif MODE == 10
printf("MODE: %i\n\tTESTING ", MODE);
printf("CONVERTING STRING TO DISTANCES\n");
srand(time(NULL));
printf("enter string to convert to distance: ");
char *input;
input = inputString(stdin);
struct coordinate data[strlen(input)];
for(unsigned int i=0; i<strlen(input); ++i){
printf("%c:\t", input[i]);
converttopoint(&data[i], (uint8_t)(input[i]));
printf("%23.10Lf,%23.10Lf\n", data[i].x, data[i].y);
}
printf("Key1:\t");
struct coordinate key1;
genkeypointrnd(&key1);
printf("%23.10Lf,%23.10Lf\n", key1.x, key1.y);
for(unsigned int i=0; i<strlen(input); ++i){
long double dist = calcdist(data[i], key1);
printf("Dist:\t%23.10Lf\n", dist);
}
free(input);
#elif MODE == 11
// for i in {32..126};do printf "\x$(printf %x $i): "; printf "\x$(printf %x $i)\n" | ./DBPBE | tail -1 | awk '{print $2}';done
printf("MODE: %i\n\tTESTING ", MODE);
printf("CONVERTING TO AND FROM DISTANCES WITH CHARS\n");
srand(time(NULL));
uint8_t input;
printf("enter data char: ");
scanf(" %c",&input);
printf("Data:\t");
struct coordinate data;
converttopoint(&data, input);
printf("%23.10Lf,%23.10Lf\n", data.x, data.y);
printf("Key1:\t");
struct coordinate key1;
genkeypointrnd(&key1);
printf("%23.10Lf,%23.10Lf\n", key1.x, key1.y);
long double dist1 = calcdist(data, key1);
printf("\tDIST: %Lf\n", dist1);
printf("Key2:\t");
struct coordinate key2;
genkeypointrnd(&key2);
printf("%23.10Lf,%23.10Lf\n", key2.x, key2.y);
long double dist2 = calcdist(data, key2);
printf("\tDIST: %Lf\n", dist2);
printf("Key3:\t");
struct coordinate key3;
genkeypointrnd(&key3);
printf("%23.10Lf,%23.10Lf\n", key3.x, key3.y);
long double dist3 = calcdist(data, key3);
printf("\tDIST: %Lf\n", dist3);
struct coordinate dataout;
dataout = calccord(dist1, dist2, dist3, key1, key2, key3);
printf("data:\t%c\n", converttodata(dataout));
#else
printf ("nothing to do for mode \"%i\"\n", MODE);
#endif
return 0;
}
Loading…
Cancel
Save