Three Dimensional Encryption

New visualization method

Bit Level Precision

By Anthony Matarazzo

Table of Contents



Introduction

Encrypt means to put (computer data) into a coded form. In the past, many different types of algorithms were used to code data. Most times, serious encryption algorithms, are used and are of interest by government bodies. This is because electronic communication is very fluid and tracing information id tedious for these parties.

In the past, the most widely known encryption success was Enigma. The Enigma machine is a German electro-mechanical rotor machine that changes character set upon each key press. In 1932, the Polish Cipher Bureau first broke the code. During World War II, many communications were successfully interpreted that aided in winning complex war battles. The machine had accessories developed that would print.

The three dimensional encryption algorithm uses data structures to represent bit information within the byte using coordinates within space. The space is defined to be a cube. The dimensions of the object, can also be exchanged or re-dimensioned to have a different length, width, and height. Each of the functions defined within this algorithm use these measurements to apply bounds upon the loop iterations. Operations are performed based upon a password or random private key. This key is needed to decode the information.

See Also

Random Numbers

Making a Cube

Importing the data into a logical data structure is accomplished using bit wise and. The powers of two, 1, 2, 4, 8, 16, 32, 64, 128 are position according to a bit location within a byte. Represented traditionally with the right most digit being the start - 1. Then moving left to 2^1=2, 2^2=4, etc. By calculating the total number of bytes in the package, 8*length produces the bit length of the package. Using a rounded up cube root of this product will give an approximation to the necessary bounds needed to host the data. Implementing standard loop counters for x,y and Z incrementing at each insertion will enable calculation of the bit location. There will usually be a segment upon the end that will need to be filled in because of the data not being a perfect cube in size. The extra data will need to be maintained even if the cube grows because all operations will depend on data passing through this location.

Bitwise Operators

Large Unique Key

Encryption Operations

API Name standards for implementation

NIST API

In Place Bit Editing

NOTE: This code is not complete yet. Updates will arrive as the book is developed further. You are invited to review.

The code below is a C example of the Cube Encryption Algorithm.

C
  1. /**************************************************************
  2. Author: Anthony Matarazzo www.AlienTimes.com
  3.  
  4. Description:
  5.  
  6. A bit level encryption algorithm designed for financial
  7. processing upon the Internet. The program uses private keys
  8. and can select several portions from a larger key.
  9. The program divides a string of data into three dimensional
  10. structures that represent the information using binary
  11. within a three dimensional space. The information is stored
  12. inside a cube shape conceptually. Positions of the bits are changed
  13. based upon the data of the password. The password is the most important feature,
  14. operating as an instruction. The details of the password bytes must be known
  15. to decrypt. Since the algorithm operatins as a chain, cube, next frames rely more
  16. upon the previous operation. One operation incorrect and the hacker
  17. is deprived.
  18.  
  19. Random data as a pure source is easier to generate in an analog universe.
  20.  
  21. ***************************************************************/
  22.  
  23. /* Additional research options -
  24.  
  25. - placing false information into the cube and then rolling changes to a specific point in time
  26.   will add complexity to decryption. Time
  27. - Specifying character set, 5-bit all caps - 8 bit ASCII - Unicode exceptions
  28. - large file handling
  29. - package format for multiple files
  30. - compression without signature
  31. - visualization of the data - 3d cube rotation of bits during operation
  32. - testing and results section
  33. - server - client handshake
  34. - lib implementation
  35. - C++ core implementation
  36. - COM implementation
  37. - Java Implementation
  38. - library for opening an encrypted channel using this method - winsock -
  39.  
  40. */
  41.  
  42. #include <cstdlib>
  43. #include <iostream>
  44. #include <bitset>
  45. #include <vector>
  46.  
  47. #include <stdio.h>
  48. #include <math.h>
  49.  
  50. using namespace std;
  51.  
  52. #include "RandomNumber.h"
  53. #include "BitEncryption.h"
  54.  
  55.  
  56.  
  57. BitEncryption::BitEncryption() {
  58. msData=0x00;
  59. mlDataSize=0;
  60. msOutput=0x00;
  61. mlOutputSize=0;
  62. msKey=0x00;
  63. mlKeySize=0;
  64. mlCubeSize=0;
  65. mlWidth=0;
  66. mlHeight=0;
  67. mRandomNumber=0x00;
  68. }
  69.  
  70. BitEncryption::‾BitEncryption() {
  71. if(msData) delete []msData;
  72. if(msOutput) delete []msOutput;
  73. if(msKey) delete []msKey;
  74. if(mRandomNumber) delete mRandomNumber;
  75. }
  76.  
  77.  
  78. /**********************************************************
  79. float CubeRoot(float x)
  80.  
  81. The function returns the cube root of the passed parameter
  82.   - The value to calculate the cube root of
  83.   - the data
  84.  
  85. * The program uses the Interate portion which is
  86.   less precise. The extra information is not needed.
  87.   Where the function is used, the value is rounded.
  88.  
  89. ===================================================================
  90. Function Source: http://people.freebsd.org/‾lstewart/references/apple_tr_kt32_cuberoot.pdf
  91.   By
  92.   Ken Turkowski, turk@apple.com
  93. **********************************************************/
  94.  
  95. float BitEncryption::CubeRoot(float x)
  96. {
  97. float fr, r;
  98. int ex, shx;
  99.  
  100. /* Argument reduction */
  101. fr = frexp(x, &ex); /* separate into mantissa and exponent */
  102. shx = ex % 3;
  103. if (shx > 0)
  104. shx -= 3; /* compute shx such that (ex - shx) is divisible by 3 */
  105. ex = (ex - shx) / 3; /* exponent of cube root */
  106. fr = ldexp(fr, shx);
  107.  
  108. /* Compute seed with a quadratic approximation */
  109. fr = (-0.46946116F * fr + 1.072302F) * fr + 0.3812513F;/* 0.5<=fr<1 */
  110. r = ldexp(fr, ex); /* 6 bits of precision */
  111. /* Newton-Raphson iterations */
  112. r = (float)(2.0/3.0) * r + (float)(1.0/3.0) * x / (r * r); /* 12 bits */
  113. r = (float)(2.0/3.0) * r + (float)(1.0/3.0) * x / (r * r); /* 24 bits */
  114.  
  115. #if 0
  116. /* Use quartic rational polynomial with error < 2^(-24) */
  117. fr = ((((45.2548339756803022511987494 * fr +
  118. 192.2798368355061050458134625) * fr +
  119. 119.1654824285581628956914143) * fr +
  120. 13.43250139086239872172837314) * fr +
  121. 0.1636161226585754240958355063)
  122. /
  123. ((((14.80884093219134573786480845 * fr +
  124. 151.9714051044435648658557668) * fr +
  125. 168.5254414101568283957668343) * fr +
  126. 33.9905941350215598754191872) * fr +
  127. 1.0);
  128. r = ldexp(fr, ex); /* 24 bits of precision */
  129. #endif
  130.  
  131. return(r);
  132. }
  133.  
  134.  
  135.  
  136. /*****************************************************
  137.  The routine tests if a bit is on within the x, y, z
  138.   state within the unsigned char stream
  139.  *****************************************************/
  140. void inline BitEncryption::SetBit(long x,long y, long z, bool rbBit)
  141. {
  142. long lByteIndex;
  143. int iShiftLeft;
  144. long lBitIndex;
  145. float fTmp;
  146.  
  147. // calculate the size of the cube.
  148. // other choice is to change the cube to rectangle
  149. fTmp=CubeRoot(mlDataSize*8);
  150. fTmp+=.9;
  151. mlCubeSize=(long) fTmp;
  152. mlCubeSize=(long) fTmp;
  153.  
  154. lBitIndex=(x+ (y*mlCubeSize) + (mlCubeSize*mlCubeSize*z));
  155. lByteIndex=lBitIndex / 8;
  156. iShiftLeft=lBitIndex % 8;
  157. unsigned char cTmp;
  158.  
  159. if(rbBit){
  160. cTmp=1<<iShiftLeft;
  161. msData[lByteIndex]|=cTmp;
  162. } else {
  163. msData[lByteIndex]^=‾cTmp;
  164. }
  165.  
  166. }
  167.  
  168. bool inline BitEncryption::GetBit(long x,long y, long z)
  169. {
  170. long lByteIndex;
  171. int iShiftLeft;
  172. long lBitIndex;
  173. bool bRet;
  174. float fTmp;
  175.  
  176. // calculate the size of the cube.
  177. // other choice is to change the cube to rectangle
  178. fTmp=CubeRoot(mlDataSize*8);
  179. fTmp+=.9;
  180. mlCubeSize=(long) fTmp;
  181. mlCubeSize=(long) fTmp;
  182.  
  183. lBitIndex=(x+ (y*mlCubeSize) + (mlCubeSize*mlCubeSize*z));
  184. lByteIndex=lBitIndex / 8;
  185. iShiftLeft=lBitIndex % 8;
  186. if(msData[lByteIndex]&(1<<iShiftLeft) == 1) {
  187. bRet=true;
  188. } else {
  189. bRet=false;
  190. }
  191. return(bRet);
  192.  
  193. }
  194.  
  195. /**********************************************************
  196.  
  197. **********************************************************/
  198. void inline BitEncryption::SwapBits(long lX1, long lY1, long lZ1, long lX2, long lY2, long lZ2)
  199. {
  200. bool bBitTmp1;
  201. bool bBitTmp2;
  202.  
  203. bBitTmp1=GetBit(lX1,lY1,lZ1);
  204. bBitTmp2=GetBit(lX2,lY2,lZ2);
  205. SetBit(lX1,lY1,lZ1, bBitTmp2);
  206. SetBit(lX2,lY2,lZ2, bBitTmp1);
  207. }
  208.  
  209.  
  210. /**********************************************************
  211.  
  212. **********************************************************/
  213. long BitEncryption::SwapPlanes(int iDir, long lPosition, long lSeed, long lAmt)
  214. {
  215. long lRet=0;
  216. long lHash;
  217. long lp1;
  218. long lp2;
  219. long lLoop;
  220. long lLoop1;
  221. long lLoop2;
  222. long lPlane1;
  223. long lPlane2;
  224.  
  225. /* create a snapshot of the point in time of the algorithm and compress the information
  226.   using the hash function. */
  227. // dHash=HashSWA(lPosition,lSeed,msKey+lPosition,RandomLong((long) *(msKey+lPosition), lSeed*lPosition*lAmt);
  228. if(lPosition> mlKeySize-4) {
  229. lHash=(long) *(msKey+(lPosition-4));
  230. } else {
  231. lHash=(long) *(msKey+lPosition);
  232. }
  233.  
  234. /* first parameter according to algorithm has to be between
  235.   second parameter according to algorithm has to be between */
  236. lp1=lHash%31328;
  237. lp2=lSeed%30081;
  238.  
  239. /* set the uniform random number generator */
  240. mRandomNumber->RandomInitialise(lp1,lp2);
  241.  
  242. for(lLoop=0;lLoop<lAmt;lLoop++) {
  243. lPlane1=mRandomNumber->RandomLong(0, mlCubeSize);
  244. lPlane2=lPlane1;
  245. // make sure two unique planes are selected within the cube
  246. while(lPlane1==lPlane2) {
  247. lPlane2=mRandomNumber->RandomLong(0, mlCubeSize);
  248. }
  249. for(lLoop1=0;lLoop1<mlCubeSize;lLoop1++) {
  250. for(lLoop2=0;lLoop2<mlCubeSize;lLoop2++) {
  251. iDir=iDir%3;
  252. switch(iDir) {
  253. case 0:
  254. SwapBits(lPlane1,lLoop1,lLoop2, lPlane2,lLoop1,lLoop2);
  255. break;
  256. case 1:
  257. SwapBits(lLoop1,lPlane1,lLoop2, lLoop1,lPlane2,lLoop2);
  258. break;
  259. case 2:
  260. SwapBits(lLoop1,lLoop2,lPlane1, lLoop1,lLoop2,lPlane2);
  261. break;
  262. }
  263. }
  264. }
  265. }
  266.  
  267. return lRet;
  268. }
  269.  
  270.  
  271. /**********************************************************
  272.  
  273. **********************************************************/
  274. long BitEncryption::SwapRays(long lPosition, long lSeed, long lAmt)
  275. {
  276. long lRet=0;
  277.  
  278.  
  279. return lRet;
  280. }
  281.  
  282.  
  283.  
  284. /**********************************************************
  285.  
  286. **********************************************************/
  287. unsigned char *BitEncryption::GenerateBitmap(long lKeyPosition, long lSeed, long lAmt)
  288. {
  289. unsigned char *lpRet=0x00;
  290. long lLoop;
  291.  
  292. lpRet=new unsigned char[lAmt];
  293. for(lLoop=0;lLoop<lAmt;lLoop++) {
  294. lpRet[lLoop]=(unsigned char)mRandomNumber->RandomInt(0,255);
  295. }
  296.  
  297. return lpRet;
  298. }
  299.  
  300.  
  301. /**********************************************************
  302.  
  303. **********************************************************/
  304. long BitEncryption::ApplyBitmap(int iFace, unsigned char *rsBitmap, long lSize)
  305. {
  306. long lRet=0;
  307. long lX1;
  308. long lY1;
  309. long lZ1;
  310. long lLoop2;
  311. long lTmp;
  312. long lPos=0;
  313.  
  314. for(lX1=0;lX1<mlCubeSize;lX1++) {
  315. for(lY1=0;lY1<mlCubeSize;lY1++) {
  316. for(lZ1=0;lZ1<mlCubeSize;lZ1++) {
  317. switch(iFace) {
  318. case 0: // z face
  319. lTmp=lZ1+rsBitmap[lPos];
  320.  
  321. if(lTmp>mlCubeSize)
  322. lTmp=(lLoop2+rsBitmap[lPos]) % mlCubeSize;
  323.  
  324. SwapBits(lX1,lY1,lZ1, lX1,lY1,lTmp);
  325. break;
  326.  
  327. case 1:
  328. lTmp=lY1+rsBitmap[lPos];
  329.  
  330. if(lTmp>mlCubeSize)
  331. lTmp=(lY1+rsBitmap[lPos]) % mlCubeSize;
  332.  
  333. SwapBits(lX1,lY1,lZ1, lX1,lTmp,lZ1);
  334. break;
  335. case 2:
  336. lTmp=lX1+rsBitmap[lPos];
  337.  
  338. if(lTmp>mlCubeSize)
  339. lTmp=(lX1+rsBitmap[lPos]) % mlCubeSize;
  340.  
  341. SwapBits(lX1,lY1,lZ1, lTmp,lY1,lZ1);
  342. break;
  343. }
  344. lPos++;
  345. if(lPos>lSize) {
  346. lPos=0;
  347. }
  348. }
  349. }
  350. }
  351. return lRet;
  352. }
  353.  
  354.  
  355.  
  356. /**********************************************************
  357.  
  358. **********************************************************/
  359. long BitEncryption::RotateXPlane(long lPosition, long lSeed, long lAmt)
  360. {
  361. long lRet=0;
  362.  
  363.  
  364. return lRet;
  365. }
  366.  
  367.  
  368. /**********************************************************
  369.  
  370. **********************************************************/
  371. long BitEncryption::RotateYPlane(long lPosition, long lSeed, long lAmt)
  372. {
  373. long lRet=0;
  374.  
  375.  
  376. return lRet;
  377. }
  378.  
  379.  
  380. /**********************************************************
  381.  
  382. **********************************************************/
  383. long BitEncryption::RotateZPlane(long lPosition, long lSeed, long lAmt)
  384. {
  385. long lRet=0;
  386.  
  387.  
  388. return lRet;
  389. }
  390.  
  391.  
  392.  
  393. /**********************************************************
  394.  
  395. **********************************************************/
  396. long BitEncryption::GenerateNonlinearPath(vector<cBitPoint>& rvPath, long lKeyPosition, long lSeed)
  397. {
  398. long lRet=0;
  399.  
  400.  
  401. return lRet;
  402. }
  403.  
  404.  
  405. /**********************************************************
  406.  
  407. **********************************************************/
  408. long BitEncryption::GenerateSpiralPath(vector<cBitPoint>& rvPath, long lKeyPosition, long lSeed)
  409. {
  410.  
  411. long lRet=0;
  412.  
  413.  
  414.  
  415. return lRet;
  416. }
  417.  
  418.  
  419. /**********************************************************
  420.  
  421. **********************************************************/
  422. long BitEncryption::GenerateCurve(vector<cBitPoint>& rvPath, long lKeyPosition, long lSeed)
  423. {
  424. long lRet=0;
  425.  
  426.  
  427. return lRet;
  428. }
  429.  
  430.  
  431. /**********************************************************
  432.  
  433. **********************************************************/
  434. long BitEncryption::SwapPaths(vector<cBitPoint>& PathA, vector<cBitPoint>& PathB)
  435. {
  436. long lRet=0;
  437.  
  438.  
  439. return lRet;
  440. }
  441.  
  442. /**********************************************************
  443.  
  444. **********************************************************/
  445. long BitEncryption::PushRay(long lPosition, long lSeed, long lAmt)
  446. {
  447. long lRet=0;
  448.  
  449.  
  450. return lRet;
  451. }
  452.  
  453.  
  454. /**********************************************************
  455.  
  456. **********************************************************/
  457. long BitEncryption::PushPath(vector<cBitPoint>& PathA, long lKeyPosition, long lSeed )
  458. {
  459. long lRet=0;
  460. // vector<cBitPoint>::iterator p2;
  461.  
  462. for (vector<cBitPoint>::iterator p=PathA.begin(); p!=PathA.end(); ++p) {
  463. if(p==PathA.begin()) {
  464. // p2=PathA.end();
  465. // SwapBits(p.x, p.y, p.z, p2.x, p2.y, p2.z);
  466. } else {
  467. // p2=p+1;
  468. // SwapBits(p.x, p.y, p.z, p2.x, p2.y, p2.z);
  469. }
  470.  
  471. }
  472. return lRet;
  473. }
  474.  
  475.  
  476. /**********************************************************
  477.  
  478. **********************************************************/
  479. long BitEncryption::SwapSubCubes(long lPosition, long lSeed, long lAmt)
  480. {
  481. long lRet=0;
  482. long lX;
  483. long lY;
  484. long lZ;
  485. long lPointAX;
  486. long lPointAY;
  487. long lPointAZ;
  488. long lPointBX;
  489. long lPointBY;
  490. long lPointBZ;
  491. long lLoop;
  492. long lSubCube;
  493.  
  494. for(lLoop=0;lLoop<lAmt;lLoop++) {
  495. lSubCube=mlCubeSize / mRandomNumber->RandomInt(0,mlCubeSize/2);
  496. lPointAX=mRandomNumber->RandomInt(0,mlCubeSize);
  497. lPointAY=mRandomNumber->RandomInt(0,mlCubeSize);
  498. lPointAZ=mRandomNumber->RandomInt(0,mlCubeSize);
  499. lPointBX=mRandomNumber->RandomInt(0,mlCubeSize);
  500. lPointBY=mRandomNumber->RandomInt(0,mlCubeSize);
  501. lPointBZ=mRandomNumber->RandomInt(0,mlCubeSize);
  502.  
  503. for(lX=0;lX<lSubCube;lX++)
  504. for(lY=0;lY<lSubCube;lY++)
  505. for(lZ=0;lZ<lSubCube;lZ++)
  506. SwapBits(lX+lPointAX, lY+lPointAY, lZ+lPointAZ,
  507. lX+lPointBX, lY+lPointBY, lZ+lPointBZ);
  508.  
  509.  
  510.  
  511. }
  512. return lRet;
  513. }
  514.  
  515.  
  516. /**********************************************************
  517.  
  518. **********************************************************/
  519. long BitEncryption::RotateSubCube(long lPosition, long lSeed, long lAmt)
  520. {
  521. long lRet=0;
  522.  
  523.  
  524. return lRet;
  525. }
  526.  
  527.  
  528. /**********************************************************
  529.  
  530. **********************************************************/
  531. long BitEncryption::RandomizeCharacterSet(long lKeyPosition, long lSeed)
  532. {
  533. long lRet=0;
  534.  
  535.  
  536. return lRet;
  537. }
  538.  
  539.  
  540. /**********************************************************
  541. long InverseBits(lPosition, lSeed, lAmt)
  542.  
  543. The function selects a given number of points within the
  544.   cube and inverses the data;
  545.  
  546. **********************************************************/
  547. long BitEncryption::InverseBits(long lPosition, long lSeed, long lAmt)
  548. {
  549. long lRet=0;
  550. long lHash;
  551. long lp1;
  552. long lp2;
  553. long lLoop;
  554.  
  555. long lX1;
  556. long lY1;
  557. long lZ1;
  558. bool bBit;
  559.  
  560. /* create a snapshot of the point in time of the algorithm and compress the information
  561.   using the hash function. */
  562. // dHash=HashSWA(lPosition,lSeed,msKey+lPosition,RandomLong((long) *(msKey+lPosition), lSeed*lPosition*lAmt);
  563. if(lPosition> mlKeySize-4) {
  564. lHash=(long) *(msKey+(lPosition-4));
  565. } else {
  566. lHash=(long) *(msKey+lPosition);
  567. }
  568.  
  569. /* first parameter according to algorithm has to be between
  570.   second parameter according to algorithm has to be between */
  571. lp1=lHash%31328;
  572. lp2=lSeed%30081;
  573.  
  574. /* set the uniform random number generator */
  575. mRandomNumber->RandomInitialise(lp1,lp2);
  576.  
  577. for(lLoop=0;lLoop<lAmt;lLoop++) {
  578.  
  579. lX1=mRandomNumber->RandomLong(0, mlCubeSize);
  580. lY1=mRandomNumber->RandomLong(0, mlCubeSize);
  581. lZ1=mRandomNumber->RandomLong(0, mlCubeSize);
  582.  
  583. bBit=GetBit(lX1,lY1,lZ1);
  584. if(bBit)
  585. SetBit(lX1,lY1,lZ1,false);
  586. else
  587. SetBit(lX1,lY1,lZ1,true);
  588. }
  589.  
  590. return lRet;
  591. }
  592.  
  593. /**********************************************************
  594.  
  595. **********************************************************/
  596. long BitEncryption::VariableMatrixGroupOddEvenSwap(long lPosition, long lSeed, long lAmt)
  597. {
  598. long lRet=0;
  599.  
  600.  
  601. return lRet;
  602. }
  603.  
  604.  
  605. /**********************************************************
  606.  
  607. **********************************************************/
  608. long BitEncryption::NoiseExpansion(long lPosition, long lSeed, long lAmt)
  609. {
  610. long lRet=0;
  611.  
  612.  
  613. return lRet;
  614. }
  615.  
  616.  
  617. /**********************************************************
  618. int Encrypt(char *szPassword, char *szData, char *szOutput)
  619.  
  620. The main function to invoke.
  621.  
  622.   - the password
  623.   - the data
  624.   - place for the output
  625.  
  626. **********************************************************/
  627. #define MAX_OPERATIONS 21
  628. long BitEncryption::Encrypt(unsigned char *sInput, long lInputSize,
  629. unsigned char *szKey, long lKeySize, unsigned char **szOutput)
  630. {
  631. long lOperation=0;
  632. long lPosition=0;
  633. unsigned char *pBitmap;
  634. cBitPoint lP1;
  635. cBitPoint lP2;
  636. unsigned char *lpchKey;
  637. long lSeed=0;
  638. long lAmt=0;
  639. long lDir=0;
  640. vector<cBitPoint> lPath1;
  641. vector<cBitPoint> lPath2;
  642. RandomNumber *pLocalRandomAmt;
  643.  
  644.  
  645. mRandomNumber=new RandomNumber();
  646. pLocalRandomAmt=new RandomNumber(mRandomNumber->RandomInt(0,30000),mRandomNumber->RandomInt(0,30000));
  647.  
  648. /* A Usual set for the encryption algorithm should be
  649.   measured to be a certain size. This will give a rating to the
  650.   cipher strength that is proportional to the size. */
  651. mlDataSize=lInputSize;
  652. msData=new unsigned char[mlDataSize];
  653. memcpy(msData,sInput,lInputSize);
  654. mlOutputSize=mlDataSize;
  655.  
  656. // calculate the size of the cube
  657. float fTmp=CubeRoot(mlDataSize*8);
  658. fTmp+=.9;
  659. mlCubeSize=(long) fTmp;
  660.  
  661.  
  662. mlKeySize=lKeySize;
  663. msKey=new unsigned char[mlKeySize];
  664. memcpy(msKey,szKey, mlKeySize);
  665.  
  666.  
  667. lpchKey=szKey;
  668. lPosition=0;
  669. while(lPosition<lKeySize) {
  670. unsigned char cTmp=(unsigned char)(*lpchKey);
  671. int iTmp=cTmp / MAX_OPERATIONS;
  672. int iTmp2=cTmp - (iTmp*MAX_OPERATIONS);
  673. lOperation=iTmp2;
  674. if(lOperation==0) lOperation=1;
  675.  
  676. lAmt=pLocalRandomAmt->RandomInt(0,10);
  677. lSeed=pLocalRandomAmt->RandomInt(0,32000);
  678.  
  679. /* perform operations based upon the password */
  680. switch(lOperation) {
  681.  
  682. /* swap lAmt planes of a given face. */
  683. case 1:
  684. SwapPlanes(0, lPosition, lSeed, lAmt);
  685. break;
  686.  
  687. case 2:
  688. SwapPlanes(1, lPosition, lSeed, lAmt);
  689. break;
  690.  
  691. case 3:
  692. SwapPlanes(2, lPosition, lSeed, lAmt);
  693. break;
  694.  
  695. /* swap two rays of data upon a given face. That is the bits that follow
  696.   the selected point upon the face are swap with the other. Since the face
  697.   may be different for one ray and the other, The data bits within path are
  698.   recorded and then the information is swapped. */
  699.  
  700. case 4:
  701. SwapRays(lPosition, lSeed, lAmt);
  702. break;
  703.  
  704. /* A cube has six sides. Given a face, a point is selected within the face.
  705.   This information is pushed through and the ray data rolled back into the
  706.   other side of the cube. A direction is established with an amount to roll.
  707.   The direction is shown by the sign of the amount - which is a logical face. */
  708. case 5:
  709. PushRay(lPosition, lSeed, lAmt);
  710. break;
  711.  
  712.  
  713. /* apply a one dimension bitmap impression to a face */
  714. case 8:
  715. pBitmap=0x00;
  716. pBitmap=GenerateBitmap(lPosition, lSeed, lAmt);
  717. ApplyBitmap(0, pBitmap, lAmt);
  718. delete []pBitmap;
  719. break;
  720.  
  721. case 9:
  722. pBitmap=0x00;
  723. pBitmap=GenerateBitmap(lPosition, lSeed, lAmt);
  724. ApplyBitmap(1, pBitmap, lAmt);
  725. delete []pBitmap;
  726. break;
  727.  
  728.  
  729. case 10:
  730. pBitmap=0x00;
  731. pBitmap=GenerateBitmap(lPosition, lSeed, lAmt);
  732. ApplyBitmap(2, pBitmap, lAmt);
  733. delete []pBitmap;
  734. break;
  735.  
  736. /* rotate a plane within the cube */
  737. case 11:
  738. RotateXPlane(lPosition, lSeed, lAmt);
  739. break;
  740.  
  741. case 12:
  742. RotateYPlane(lPosition, lSeed, lAmt);
  743. break;
  744.  
  745. case 13:
  746. RotateZPlane(lPosition, lSeed, lAmt);
  747. break;
  748.  
  749. /* Generate two nonlinear paths from one face to the otherside
  750.   then swap the two. WHen the paths are not of equal size,
  751.   information resdue is still maintained.
  752.   - within the cube a path is generated that is shaped like a tree branch.
  753.   the information along the path is extracted. A second path is generated
  754.   that contains the same amount of information. This information is extracted.
  755.   The two information branches are swapped along the two paths. */
  756. case 14:
  757. // generates numbers for the path
  758. lPath1.clear();
  759. lPath2.clear();
  760. GenerateNonlinearPath(lPath1, lPosition, lSeed);
  761. GenerateNonlinearPath(lPath2, lPosition, lSeed);
  762. SwapPaths(lPath1, lPath2);
  763. lPath1.clear();
  764. lPath2.clear();
  765. break;
  766.  
  767.  
  768. /* generate a random order for the character set. */
  769. case 15:
  770. RandomizeCharacterSet(lPosition, lSeed);
  771. break;
  772.  
  773. case 16:
  774. GenerateSpiralPath(lPath1, lPosition, lSeed);
  775. GenerateSpiralPath(lPath2, lPosition, lSeed);
  776. SwapPaths(lPath1, lPath2);
  777. break;
  778.  
  779.  
  780. /* swap two sub cubes within the larger cube */
  781. case 17:
  782. SwapSubCubes(lPosition, lSeed, lAmt);
  783. break;
  784.  
  785. /* rotate a sube cube within the larget cube */
  786. case 18:
  787. RotateSubCube(lPosition, lSeed, lAmt);
  788. break;
  789.  
  790. case 19:
  791. /* representing each cube position (part) as being a distinct segment, the segment length
  792.   derived using a uniform random, enables a relationship to exist with other portions of the cube.
  793.   The ability to tie this relationship to visually disjointed portions of the space
  794.   will amplify complexity of the decryption. This ties relationships using proportional distances
  795.   to the face. Changing faces using a uniform random number seeded by the password position
  796.   enables decryption using the key.*/
  797. VariableMatrixGroupOddEvenSwap(lPosition, lSeed, lAmt);
  798. break;
  799.  
  800. case 20:
  801. /* the algorithm will expand the cube with a small amount of data. One pass will not
  802.   double the suze of the cube. The amount of data added, the data and the position of the data
  803.   are based upon the random uniform seeded by location. It is expected that multiple
  804.   passes through this routine is accomplished using the hidden instruction key. */
  805. NoiseExpansion(lPosition, lSeed, lAmt);
  806.  
  807. break;
  808.  
  809. case 21:
  810. /* This routine uses a curved line segment with one bend. The height of the form
  811.   will be determined by its position within space. The bend will occur at a uniform
  812.   position and effect directly the height. Once a curve shape is calculated, this information
  813.   is used within the three planes, x,y,z. A rotation of information along this curve occurs
  814.   between the two planes. So for example x=z y=x
  815.  
  816.   See: B騷ier curve
  817.   http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  818.  
  819.   */
  820. lPath1.clear();
  821. lPath2.clear();
  822. GenerateCurve(lPath1, lPosition, lSeed);
  823. GenerateCurve(lPath2, lPosition, lSeed);
  824. SwapPaths(lPath1, lPath2);
  825. break;
  826.  
  827. case 22:
  828. /* this option will erase data or reverse the bit status upon a
  829.   select group of pixels. Using the UNARY operation, 1=0 and 0=1,
  830.   the operation can be undone. A good transform for basic data,
  831.   the selection of x,y,z coordinates is particular. */
  832. InverseBits(lPosition, lSeed, lAmt);
  833. break;
  834.  
  835.  
  836. default:
  837. break;
  838.  
  839. }
  840. lpchKey++;
  841. lPosition++;
  842. }
  843.  
  844. delete pLocalRandomAmt;
  845. pLocalRandomAmt=0x00;
  846.  
  847. delete mRandomNumber;
  848. mRandomNumber=0x00;
  849.  
  850. *szOutput= new unsigned char[mlOutputSize+1];
  851. memset(*szOutput,0x00,mlOutputSize+1);
  852. memcpy(*szOutput, msData,mlOutputSize);
  853. return(mlOutputSize);
  854. }
  855.  
  856. /**********************************************************
  857. int main(int argc, char **argv)
  858.  
  859. The main function - called at start.
  860.   - the number of parameters
  861.   - the parameters
  862.  
  863. **********************************************************/
  864. long BitEncryption::Decrypt(unsigned char *sInput, long lInputSize,
  865. unsigned char *szKey, long lKeySize, unsigned char **szOutput)
  866. {
  867. long lRet=0;
  868.  
  869.  
  870. return(lRet);
  871. }
  872.  
  873.  
  874. /**********************************************************
  875. int main(int argc, char **argv)
  876.  
  877. The main function - called at start.
  878.   - the number of parameters
  879.   - the parameters
  880.  
  881. **********************************************************/
  882. int main(int argc, char **argv)
  883. {
  884. int n;
  885. BitEncryption *cBits = new BitEncryption();
  886. unsigned char *szPassword=new unsigned char[255];
  887. unsigned char *szData=new unsigned char[255];
  888. unsigned char *szOut=0x00;
  889. long lOutputSize;
  890.  
  891. /*
  892. if (argc < 2) {
  893. printf("usage: encrypt n¥n"
  894. "password.txt data.txt output.txt [-encrypt -decrypt]¥n");
  895. return 1;
  896. }*/
  897.  
  898. memset(szPassword,255,0x00);
  899. memset(szData,255,0x00);
  900.  
  901. strcpy((char *)szPassword,"THEPASSWORD");
  902.  
  903. strcpy((char *)szData,"ABCDEFHIJKLMNOPQRSTUVWXYZ");
  904.  
  905.  
  906. printf("password = %s¥n data = %s¥n", szPassword, szData);
  907.  
  908. lOutputSize=cBits->Encrypt(szData, strlen((char *)szData), szPassword, strlen((char *)szPassword), &szOut);
  909.  
  910. printf("data = %s¥n", szOut);
  911.  
  912.  
  913. delete []szData;
  914. delete []szPassword;
  915. delete []szOut;
  916.  
  917. system("PAUSE");
  918. return EXIT_SUCCESS;
  919. }
  920.  
C
  1. #include <vector>
  2.  
  3. class cBitPoint {
  4. public:
  5. int x;
  6. int y;
  7. int z;
  8.  
  9. cBitPoint() {};
  10. ~cBitPoint() {};
  11. };
  12.  
  13. bool operator==(const cBitPoint& a, const cBitPoint& b) {
  14. return a.x == b.x && a.y == b.y && a.z == b.z;
  15. }
  16.  
  17. bool operator!=(const cBitPoint& a, const cBitPoint& b)
  18. {
  19. return !(a.x == b.x && a.y == b.y && a.z == b.z);
  20. }
  21.  
  22. /*******************************
  23.   The Main Class
  24. *******************************/
  25. class BitEncryption {
  26.  
  27.  
  28.  
  29. public:
  30. BitEncryption();
  31. ~BitEncryption();
  32. long Encrypt(unsigned char *sInput, long lInputSize,
  33. unsigned char *szKey, long lKeySize, unsigned char **szOutput);
  34. long Decrypt(unsigned char *sInput, long lInputSize,
  35. unsigned char *szKey, long lKeySize, unsigned char **szOutput);
  36.  
  37.  
  38. private:
  39. float CubeRoot(float x);
  40. bool GetBit(long y, long y, long z);
  41. void SetBit(long x, long y, long z, bool rbVal);
  42. void SwapBits(long X1, long y1, long z1, long X2, long y2, long z2 );
  43.  
  44. // Operations
  45. long SwapPlanes(int iDir, long lPosition, long lSeed, long lAmt);
  46. long SwapRays(long lPosition, long lSeed, long lAmt);
  47.  
  48. unsigned char *GenerateBitmap(long lKeyPosition, long lSeed, long lAmt);
  49. long ApplyBitmap(int iFace, unsigned char *rsBitmap, long lSize);
  50.  
  51. long RotateXPlane(long lPosition, long lSeed, long lAmt);
  52. long RotateYPlane(long lPosition, long lSeed, long lAmt);
  53. long RotateZPlane(long lPosition, long lSeed, long lAmt);
  54.  
  55.  
  56. long GenerateNonlinearPath(vector<cBitPoint>& rPath, long lKeyPosition, long lSeed);
  57. long GenerateSpiralPath(vector<cBitPoint>& rPath, long lKeyPosition, long lSeed);
  58. long GenerateCurve(vector<cBitPoint>& rPath,long lKeyPosition, long lSeed);
  59.  
  60. long SwapPaths(vector<cBitPoint>& PathA, vector<cBitPoint>& PathB);
  61. long PushPath(vector<cBitPoint>& PathA, long lKeyPosition, long lSeed );
  62. long PushRay(long lPosition, long lSeed, long lAmt);
  63.  
  64. long SwapSubCubes(long lPosition, long lSeed, long lAmt);
  65. long RotateSubCube(long lPosition, long lSeed, long lAmt);
  66.  
  67. long RandomizeCharacterSet(long lKeyPosition, long lSeed);
  68. long InverseBits(long lPosition, long lSeed, long lAmt);
  69. long VariableMatrixGroupOddEvenSwap(long lPosition, long lSeed, long lAmt);
  70. long NoiseExpansion(long lPosition, long lSeed, long lAmt);
  71.  
  72. // changing the byte base does have noticeable signatures.
  73. // and must be effectively synchronized to achieve hidden and
  74. // obscure results.
  75. long ChangeByteBase(long lKeyPosition, long lSeed);
  76.  
  77. private:
  78. unsigned char *msData;
  79. long mlDataSize;
  80. unsigned char *msOutput;
  81. long mlOutputSize;
  82. unsigned char *msKey;
  83. long mlKeySize;
  84. long mlCubeSize;
  85. RandomNumber *mRandomNumber;
  86. long mlWidth;
  87. long mlHeight;
  88.  
  89. };
  90.  
C
  1. #include "RandomNumber.h"
  2. #include <math.h>
  3. /*
  4.   This Random Number Generator is based on the algorithm in a FORTRAN
  5.   version published by George Marsaglia and Arif Zaman, Florida State
  6.   University; ref.: see original comments below.
  7.   At the fhw (Fachhochschule Wiesbaden, W.Germany), Dept. of Computer
  8.   Science, we have written sources in further languages (C, Modula-2
  9.   Turbo-Pascal(3.0, 5.0), Basic and Ada) to get exactly the same test
  10.   results compared with the original FORTRAN version.
  11.   April 1989
  12.   Karl-L. Noell <NOELL@DWIFH1.BITNET>
  13.   and Helmut Weber <WEBER@DWIFH1.BITNET>
  14.  
  15.   This random number generator originally appeared in "Toward a Universal
  16.   Random Number Generator" by George Marsaglia and Arif Zaman.
  17.   Florida State University Report: FSU-SCRI-87-50 (1987)
  18.   It was later modified by F. James and published in "A Review of Pseudo-
  19.   random Number Generators"
  20.   THIS IS THE BEST KNOWN RANDOM NUMBER GENERATOR AVAILABLE.
  21.   (However, a newly discovered technique can yield
  22.   a period of 10^600. But that is still in the development stage.)
  23.   It passes ALL of the tests for random number generators and has a period
  24.   of 2^144, is completely portable (gives bit identical results on all
  25.   machines with at least 24-bit mantissas in the floating point
  26.   representation).
  27.   The algorithm is a combination of a Fibonacci sequence (with lags of 97
  28.   and 33, and operation "subtraction plus one, modulo one") and an
  29.   "arithmetic sequence" (using subtraction).
  30.  
  31.   Use IJ = 1802 & KL = 9373 to test the random number generator. The
  32.   subroutine RANMAR should be used to generate 20000 random numbers.
  33.   Then display the next six random numbers generated multiplied by 4096*4096
  34.   If the random number generator is working properly, the random numbers
  35.   should be:
  36.   6533892.0 14220222.0 7275067.0
  37.   6172232.0 8354498.0 10633180.0
  38. */
  39.  
  40. RandomNumber::RandomNumber()
  41. {
  42. test=FALSE;
  43.  
  44. }
  45.  
  46. RandomNumber::~RandomNumber()
  47. {
  48.  
  49. }
  50.  
  51.  
  52. /*
  53.   This is the initialization routine for the random number generator.
  54.   NOTE: The seed variables can have values between: 0 <= IJ <= 31328
  55.   0 <= KL <= 30081
  56.   The random number sequences created by these two seeds are of sufficient
  57.   length to complete an entire calculation with. For example, if sveral
  58.   different groups are working on different parts of the same calculation,
  59.   each group could be assigned its own IJ seed. This would leave each group
  60.   with 30000 choices for the second seed. That is to say, this random
  61.   number generator can create 900 million different subsequences -- with
  62.   each subsequence having a length of approximately 10^30.
  63. */
  64. void RandomNumber::RandomInitialise(int ij,int kl)
  65. {
  66. double s,t;
  67. int ii,i,j,k,l,jj,m;
  68.  
  69. /*
  70.   Handle the seed range errors
  71.   First random number seed must be between 0 and 31328
  72.   Second seed must have a value between 0 and 30081
  73.   */
  74. if (ij < 0 || ij > 31328 || kl < 0 || kl > 30081) {
  75. ij = 1802;
  76. kl = 9373;
  77. }
  78.  
  79. i = (ij / 177) % 177 + 2;
  80. j = (ij % 177) + 2;
  81. k = (kl / 169) % 178 + 1;
  82. l = (kl % 169);
  83.  
  84. for (ii=0; ii<97; ii++) {
  85. s = 0.0;
  86. t = 0.5;
  87. for (jj=0; jj<24; jj++) {
  88. m = (((i * j) % 179) * k) % 179;
  89. i = j;
  90. j = k;
  91. k = m;
  92. l = (53 * l + 1) % 169;
  93. if (((l * m % 64)) >= 32)
  94. s += t;
  95. t *= 0.5;
  96. }
  97. u[ii] = s;
  98. }
  99.  
  100. c = 362436.0 / 16777216.0;
  101. cd = 7654321.0 / 16777216.0;
  102. cm = 16777213.0 / 16777216.0;
  103. i97 = 97;
  104. j97 = 33;
  105. test = TRUE;
  106. }
  107.  
  108. /*
  109.   This is the random number generator proposed by George Marsaglia in
  110.   Florida State University Report: FSU-SCRI-87-50
  111. */
  112. double RandomNumber::RandomUniform(void)
  113. {
  114. double uni;
  115.  
  116. /* Make sure the initialisation routine has been called */
  117. if (!test)
  118. RandomInitialise(1802,9373);
  119.  
  120. uni = u[i97-1] - u[j97-1];
  121. if (uni <= 0.0)
  122. uni++;
  123. u[i97-1] = uni;
  124. i97--;
  125. if (i97 == 0)
  126. i97 = 97;
  127. j97--;
  128. if (j97 == 0)
  129. j97 = 97;
  130. c -= cd;
  131. if (c < 0.0)
  132. c += cm;
  133. uni -= c;
  134. if (uni < 0.0)
  135. uni++;
  136.  
  137. return(uni);
  138. }
  139.  
  140. /*
  141.   ALGORITHM 712, COLLECTED ALGORITHMS FROM ACM.
  142.   THIS WORK PUBLISHED IN TRANSACTIONS ON MATHEMATICAL SOFTWARE,
  143.   VOL. 18, NO. 4, DECEMBER, 1992, PP. 434-435.
  144.   The function returns a normally distributed pseudo-random number
  145.   with a given mean and standard devaiation. Calls are made to a
  146.   function subprogram which must return independent random
  147.   numbers uniform in the interval (0,1).
  148.   The algorithm uses the ratio of uniforms method of A.J. Kinderman
  149.   and J.F. Monahan augmented with quadratic bounding curves.
  150. */
  151. double RandomNumber::RandomGaussian(double mean,double stddev)
  152. {
  153. double q,u,v,x,y;
  154.  
  155. /*
  156. Generate P = (u,v) uniform in rect. enclosing acceptance region
  157.   Make sure that any random numbers <= 0 are rejected, since
  158.   gaussian() requires uniforms > 0, but RandomUniform() delivers >= 0.
  159. */
  160. do {
  161. u = RandomUniform();
  162. v = RandomUniform();
  163. if (u <= 0.0 || v <= 0.0) {
  164. u = 1.0;
  165. v = 1.0;
  166. }
  167. v = 1.7156 * (v - 0.5);
  168.  
  169. /* Evaluate the quadratic form */
  170. x = u - 0.449871;
  171. y = fabs(v) + 0.386595;
  172. q = x * x + y * (0.19600 * y - 0.25472 * x);
  173.  
  174. /* Accept P if inside inner ellipse */
  175. if (q < 0.27597)
  176. break;
  177.  
  178. /* Reject P if outside outer ellipse, or outside acceptance region */
  179. } while ((q > 0.27846) || (v * v > -4.0 * log(u) * u * u));
  180.  
  181. /* Return ratio of P's coordinates as the normal deviate */
  182. return (mean + stddev * v / u);
  183. }
  184.  
  185. /*
  186.   Return random integer within a range, lower -> upper INCLUSIVE
  187. */
  188. int RandomNumber::RandomInt(int lower,int upper)
  189. {
  190. return((int)(RandomUniform() * (upper - lower + 1)) + lower);
  191. }
  192. long RandomNumber::RandomLong(long lower,long upper)
  193. {
  194. return((long)(RandomUniform() * (upper - lower + 1)) + lower);
  195. }
  196.  
  197. /*
  198.   Return random float within a range, lower -> upper
  199. */
  200. double RandomNumber::RandomDouble(double lower,double upper)
  201. {
  202. return((upper - lower) * RandomUniform() + lower);
  203. }
  204.  
  205.  
C
  1. #define FALSE 0
  2. #define TRUE 1
  3.  
  4. class RandomNumber {
  5. public:
  6. RandomNumber();
  7. RandomNumber(int ij,int kl) {RandomInitialise(ij,kl);}
  8. ~RandomNumber();
  9.  
  10. void RandomInitialise(int ij,int kl);
  11. double RandomUniform(void);
  12. double RandomGaussian(double mean,double stddev);
  13. int RandomInt(int lower,int upper);
  14. long RandomLong(long lower,long upper);
  15. double RandomDouble(double lower,double upper);
  16.  
  17. private:
  18. double u[97],c,cd,cm;
  19. int i97,j97;
  20. int test;
  21. };
  22.  

Out on the Road

Testing an algorithm of this nature can take form in many tasks. The primary tasks according to work is that the algorithm be a) precise b) robust and c) high performance. The implementation for this research project works first on precision. Precision includes many times of the algorithm running until completeness.

Statistics on Performance

Number of Operations to Bit

CPU Performance Based Upon Key Length