You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

266 lines
18 KiB

  1. // dbpbe.h is part of the DBPBE project
  2. // Copyright (C) 2020 Jacob Still jacobcstill@gmail.com
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. #ifndef __DBPBE_H__
  17. #define __DBPBE_H__
  18. #include <stdlib.h>
  19. #include <stdbool.h>
  20. #include <math.h>
  21. #include <stdint.h>
  22. #include <time.h>
  23. /*******************************************************************************
  24. * coordinate -- Struct storing the x and y components of the coordinate *
  25. * *
  26. * NOTE: *
  27. * *
  28. * HISTORY: *
  29. * 07/11/2020 - Created *
  30. * *
  31. ******************************************************************************/
  32. struct coordinate{
  33. long double x;
  34. long double y;
  35. };
  36. /*******************************************************************************
  37. * converttodata -- Converts a stored struct coordinate to an 8 bit value *
  38. * *
  39. * NOTE: *
  40. * !TODO: Issue #7 *
  41. * Shouldn't fail - needs to be tested *
  42. * *
  43. * INPUT: struct - coordinate *
  44. * *
  45. * OUTPUT: uint8_t - data that is stored from from converttopoint() *
  46. * *
  47. * HISTORY: *
  48. * 03/06/2020 - Created *
  49. * 06/12/2020 - Updated for use with new converttopoint() function *
  50. * 07/11/2020 - Adjusted for C *
  51. * *
  52. ******************************************************************************/
  53. uint8_t converttodata(struct coordinate point);
  54. /*******************************************************************************
  55. * converttopoint -- Converts an 8 bit value to a struct coordinate that is *
  56. * then stored *
  57. * *
  58. * NOTE: *
  59. * !TODO: Issue #6 *
  60. * types still need to be looked at (since using long doubles as coord type)*
  61. * 1 input is multiplied by a prime number: *
  62. * x = (input * 16785407 * 5) % 4294967295 *
  63. * y = input * 16838387 *
  64. * !NOTE: prime numbers were chosen so that any 8 bit number can't multiply *
  65. * to greater than size of long long *
  66. * *
  67. * 2 then weather or not both components of the coordinate are negative is *
  68. * calculated based on input: *
  69. * positivex = (2097593 % ((input % 43) + 1) * input * 16785407) % 2; *
  70. * positivey = (5020783 % ((input % 37) + 1) * input * 16838387) % 2; *
  71. * *
  72. * 3 the data post-decimal is then calculated based on input: *
  73. * postx = 2097593 % ((input % 43) + 1); *
  74. * posty = 5020783 % ((input % 37) + 1); *
  75. * *
  76. * 4 the post-decimal data is then divided by 10 until it is less than 1 then *
  77. * it is added to the respective component the component is then multiplied *
  78. * by -1 if it needs to be negative. *
  79. * *
  80. * INPUT: *
  81. * struct - coordinate *
  82. * input - data to be converted to a struct coordinate *
  83. * *
  84. * OUTPUT: none *
  85. * *
  86. * HISTORY: *
  87. * 03/06/2020 - Created *
  88. * 06/12/2020 - Completely Restructured how this function works *
  89. * 07/11/2020 - Adjusted for C *
  90. * *
  91. ******************************************************************************/
  92. void converttopoint(struct coordinate *point, uint8_t input);
  93. /*******************************************************************************
  94. * genkeypointrnd -- Generate key point based on rand() *
  95. * *
  96. * NOTE: *
  97. * Need to call srand(time(NULL)) once at beginning of program *
  98. * !TODO: Add Hash functionality to this as well??? *
  99. * *
  100. * !TODO: Issue #6 *
  101. * fix datatypes completely *
  102. * 1 Each bit of the pre-decimal portion of the coordinate is generated by *
  103. * std::rand() and bit shifted into place *
  104. * !NOTE: keys are 64 bits long (when they are generated) *
  105. * *
  106. * 2 Weather each component of the coordinate is negative is generated by *
  107. * std::rand() *
  108. * *
  109. * 3 The data post-decimal is generated by std::rand() *
  110. * *
  111. * The post-decimal data is divided by 10 until it is less than 1. Then it *
  112. * is added to the respective component of the coordinate. The component is *
  113. * then multiplied by -1 if it needs to be negative. *
  114. * *
  115. * INPUT: struct - coordinate *
  116. * *
  117. * OUTPUT: none *
  118. * *
  119. * HISTORY: *
  120. * 06/12/2020 - Created *
  121. * 07/11/2020 - Adjusted for C *
  122. * *
  123. ******************************************************************************/
  124. void genkeypointrnd(struct coordinate *point);
  125. /*******************************************************************************
  126. * genkeypoint -- Generate key point based on user input *
  127. * *
  128. * NOTE: *
  129. * A Hash is generated from the user input and then the same computations *
  130. * are done on it (just with different numbers) *
  131. * *
  132. * INPUT: *
  133. * struct - coordinate *
  134. * input - cstring passphrase passed in *
  135. * size - number of characters in the cstring *
  136. * *
  137. * OUTPUT: none *
  138. * *
  139. * HISTORY: *
  140. * 03/07/2020 - Created *
  141. * 03/09/2020 - Slight modification of interworkings *
  142. * 06/12/2020 - Changed to hash based key generetion *
  143. * 07/11/2020 - Adjusted for C *
  144. * *
  145. ******************************************************************************/
  146. void genkeypoint(struct coordinate *point, const char input[], int size);
  147. /*******************************************************************************
  148. * calcdist -- Calculates the distance between two keys *
  149. * *
  150. * NOTE: *
  151. * *
  152. * INPUT: data,key - coordinates to calculate distance from *
  153. * *
  154. * OUTPUT: none *
  155. * *
  156. * HISTORY: *
  157. * 05/08/2020 - Created *
  158. * 06/12/2020 - Simplified function *
  159. * 07/11/2020 - Adjusted for C *
  160. * *
  161. ******************************************************************************/
  162. long double calcdist(struct coordinate data, struct coordinate key);
  163. /*******************************************************************************
  164. * withinPercent -- Checks if two numbers are within a percentage of each other*
  165. * *
  166. * NOTE: *
  167. * *
  168. * INPUT: *
  169. * first,second - two numbers to calculate *
  170. * percent - percentage to calculate with - 20% should be passed as 20.0 *
  171. * *
  172. * OUTPUT: bool - if the numbers are within a percentage of each other or not *
  173. * *
  174. * HISTORY: *
  175. * 06/12/2020 - Created *
  176. * 07/11/2020 - Adjusted for C *
  177. * *
  178. ******************************************************************************/
  179. bool withinPercent(long double first, long double percent, long double second);
  180. /*******************************************************************************
  181. * circle_circle_intersection -- Calculates the intersection points between *
  182. * two circles *
  183. * *
  184. * NOTE: *
  185. * Based on work by Paul Bourke: *
  186. * http://paulbourke.net/geometry/circlesphere/ *
  187. * Code basically copied from Tim Voght: *
  188. * http://paulbourke.net/geometry/circlesphere/tvoght.c *
  189. * *
  190. * INPUT: respective components of two circles AND pointers to components of *
  191. * intersection points *
  192. * *
  193. * OUTPUT: int - error codes !TODO: remove error codes and make void function *
  194. * *
  195. * HISTORY: *
  196. * 05/08/2020 - Created *
  197. * 06/12/2020 - Fix function returning errors *
  198. * 07/11/2020 - Adjusted for C *
  199. * *
  200. ******************************************************************************/
  201. 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);
  202. /*******************************************************************************
  203. * get_single -- Returns the coordinate component that occurs the most *
  204. * *
  205. * NOTE: *
  206. * !TODO: Issue #7 *
  207. * Modify code to actually check which one occurs the most *
  208. * *
  209. * INPUT: x - array of components of a coordinate *
  210. * *
  211. * OUTPUT: long double - number that occurs the most in input array *
  212. * *
  213. * HISTORY: *
  214. * 05/08/2020 - Created *
  215. * 07/11/2020 - Adjusted for C *
  216. * *
  217. ******************************************************************************/
  218. long double get_single(long double x[6]);
  219. /*******************************************************************************
  220. * calccord -- Returns the coordinate that was converted into distances based *
  221. * on key points *
  222. * *
  223. * NOTE: *
  224. * Each distance has a respective key. ie, dist0 is the distance from key0 *
  225. * *
  226. * INPUT: *
  227. * dist{0-2} - three distance components *
  228. * key{0-2} - three keys *
  229. * *
  230. * OUTPUT: coordinate - the coordinate that is referred to by all the keys and *
  231. * distances *
  232. * *
  233. * HISTORY: *
  234. * 05/08/2020 - Created *
  235. * 06/12/2020 - Simplified code a bit *
  236. * 07/11/2020 - Adjusted for C *
  237. * *
  238. ******************************************************************************/
  239. struct coordinate calccord(long double dist0, long double dist1, long double dist2, struct coordinate key0, struct coordinate key1, struct coordinate key2);
  240. #endif