Advertisement
Guest User

Untitled

a guest
Oct 26th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. //============================================================================
  2. // Name        : Main.cpp
  3. // Author      : Brock Matzenbacher
  4. // Version     :
  5. // Copyright   : Pfft.
  6. // Description : Runs the BitTree
  7. //============================================================================
  8.  
  9. #include <iostream>
  10. #include "sha256.h"
  11. #include "BitTree.h"
  12.  
  13.  
  14. unsigned int hexCharToVal(char c) {
  15.     return (c >= 'a') ? (c - 'a' + 10) : (c - '0');
  16. }
  17.  
  18. int main() {
  19.     //a string to generate a hash of
  20.     std::string s = "To many this answer is less appealing than the question.";
  21.     //the hashing function returns this
  22.     //as a 64 character hex string
  23.     std::string hexStr = sha256(s);
  24.  
  25.     //where the magic happens
  26.     BitTree myTree;
  27.  
  28.     //the base bit index
  29.     unsigned int idx = 0;
  30. //parse every character
  31.     for (unsigned int i = 0; i < hexStr.length();i++) {
  32.         unsigned int val = hexCharToVal(hexStr.at(i));
  33.  
  34.         //each character represents 4 bits (0-f)
  35.         for (int j=0;j<4;j++) {
  36.             //if the bit we are examining is set
  37.             if ((val >> j) & 1) {
  38.                 myTree.set(j+idx);//add to bittree
  39.             }
  40.         }
  41.         //increment the base bit index
  42.         idx+=4;
  43.     }
  44.     //this will output the tree
  45.     myTree.visualise();
  46.     std::string str = sha256(s);
  47.     std::cout << "   ";
  48.     for (int i = 0; i < 64;i++) {
  49.         std::cout << str[i] << "   |   ";
  50.     }
  51.     std::cout << std::endl;
  52.     unsigned int full,left,right,leaf;
  53.     std::cout <<"Statistics:" <<std::endl
  54.             << "Full Nodes: " <<(full=myTree.countFullNodes())
  55.             << "\nLeft Nodes: " << (left=myTree.countLeftNodes())
  56.             << "\nRight Nodes: "<< (right=myTree.countRightNodes())
  57.             << "\nLeaf Nodes: " << (leaf=myTree.countLeafNodes());
  58.     std::cout << std::endl << myTree.compress();
  59.     return 0;
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement