Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Jul 18th, 2018 54 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. //"g++"  "main.cpp" -o "main" -lb2 -ljsoncpp
  2. #include <sstream>
  3. #include <string>
  4. #include <iostream>
  5. #include <ctime>
  6. #include <blake2.h>//libb2-dev
  7. #include <jsoncpp/json/json.h>//libjsoncpp-dev
  8. #include <iomanip>
  9.  
  10. char TOPSECRET[] = "TOPSECRET";
  11. long dateCounter = 0;
  12.  
  13. std::string gameKey(long id2=-1){
  14.  
  15.   long long id = std::time(0)*1000+dateCounter;
  16.   if(id2!=-1){
  17.     id = id2;
  18.   }
  19.   dateCounter++;
  20.  
  21.   std::stringstream inStream;
  22.   inStream << id << "|keys|" << TOPSECRET;
  23.   const std::string inString = inStream.str();
  24.   const char* in = inString.c_str();
  25.  
  26.   size_t outlen=64;
  27.   uint8_t* out = new uint8_t[outlen];
  28.   char key[] = "";
  29.   blake2b(out,in,&key,outlen,inString.length(),0);
  30.  
  31.   std::stringstream a,b,c,d;
  32.   for(int i=0;i<16;i++){
  33.     a << std::setfill('0') << std::setw(2) << std::hex << static_cast<unsigned>(out[i]);
  34.   }
  35.   for(int i=16;i<16*2;i++){
  36.     b << std::setfill('0') << std::setw(2) << std::hex << static_cast<unsigned>(out[i]);
  37.   }
  38.   for(int i=16*2;i<16*3;i++){
  39.     c << std::setfill('0') << std::setw(2) << std::hex << static_cast<unsigned>(out[i]);
  40.   }
  41.   for(int i=16*3;i<16*4;i++){
  42.     d << std::setfill('0') << std::setw(2) << std::hex << static_cast<unsigned>(out[i]);
  43.   }
  44.  
  45.   Json::Value obj(Json::objectValue);
  46.   obj["id"] = id;
  47.  
  48.   Json::Value arr(Json::arrayValue);
  49.   arr.append(a.str());
  50.   arr.append(b.str());
  51.   arr.append(c.str());
  52.   arr.append(d.str());
  53.   obj["keys"] = arr;
  54.  
  55.   Json::Writer* writer = new Json::FastWriter();
  56.   std::string jsonOut = writer->write(obj);
  57.  
  58.   delete writer;
  59.   //delete in;//WTF segfault
  60.   delete out;
  61.  
  62.   return jsonOut;
  63. }
  64.  
  65. int main(){
  66.   std::cout << gameKey();
  67. }
  68.    
  69. const TOPSECRET = "TOPSECRET", blake = require("blakejs").blake2bHex;
  70. let dateCounter = 0;
  71.  
  72. function gameKey(checkId){//per key: 34us js VS 10us c++
  73.   let id = checkId || (Date.now()/1000>>0)*1000+(dateCounter++%1000),
  74.     keys = blake(`${id}|keys|${TOPSECRET}`).match(/.{32}/g);
  75.   return {id, keys};
  76. }
  77. console.log(gameKey());
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top