flat boob theory

This commit is contained in:
malloc 2018-03-29 17:10:39 -05:00
parent 8c3469c4c1
commit c9c09c79ef
8 changed files with 103 additions and 84 deletions

View file

@ -34,6 +34,8 @@ var Entrypoint = (function () {
}; };
Entrypoint.start = function () { Entrypoint.start = function () {
var _this = this; var _this = this;
var conn = new Connection("ws://127.0.0.1:8080", []);
conn.open();
Key.init(function () { Key.init(function () {
_this.initStatus.keyInit = true; _this.initStatus.keyInit = true;
_this.initCheck(); _this.initCheck();
@ -50,7 +52,7 @@ var Entrypoint = (function () {
}); });
}; };
Entrypoint.ready = function () { Entrypoint.ready = function () {
alert("ready"); //alert("ready");
}; };
return Entrypoint; return Entrypoint;
}()); }());

View file

@ -34,6 +34,9 @@ class Entrypoint {
} }
public static start(): void { public static start(): void {
var conn = new Connection("ws://127.0.0.1:8080", []);
conn.open();
Key.init(() => { Key.init(() => {
this.initStatus.keyInit = true; this.initStatus.keyInit = true;
this.initCheck(); this.initCheck();
@ -54,6 +57,6 @@ class Entrypoint {
} }
private static ready(): void { private static ready(): void {
alert("ready"); //alert("ready");
} }
} }

Binary file not shown.

View file

@ -14,90 +14,19 @@
#include "utils/bigint.hpp" #include "utils/bigint.hpp"
int main(int argc, char **argv) { int main(int argc, char **argv) {
//auto sock = sosc::TcpClient(); sosc::TcpServer server;
sosc::TcpClient client;
std::string buffer;
/*std::string a = "this!!is!!a!!test"; server.Listen(8080);
auto b = sosc::str::split(a, "!!"); std::cout << "Listening ..." << std::endl;
std::for_each(b.begin(), b.end(), [](std::string& i) { server.Accept(&client);
std::cout << i << std::endl; std::cout << "Reading ..." << std::endl;
});*/
/*sosc::TcpClient client; while(true) {
client.Open("127.0.0.1", 1111); client.Receive(&buffer, SOSC_TCP_BLOCK);
std::cout << buffer;
client.Send("test"); }
std::string got = "abc";
while(client.IsOpen()) {
int length = client.Receive(&got);
if(length > 0)
std::cout << got << std::endl;
}*/
//std::string a = sosc::cgc::sha1("test", true);
/*sosc::cgc::Blowfish fish("TESTKEY");
std::string test = fish.Encrypt("imagine a test");
std::string testd = fish.Decrypt(test);
uint32_t teest = sosc::csprng::next<uint32_t>();
std::cout << std::hex << teest;*/
/*std::string hash = sosc::cgc::bcrypt_hash("test pwd");
std::cout << hash << std::endl;
std::cout << sosc::cgc::bcrypt_check("test pwd", hash);*/
sosc::BigUInt a, b, c;
/*a = sosc::BigUInt::GenerateRandom(128);
b = sosc::BigUInt::GenerateRandom(128);
c = sosc::BigUInt::GenerateRandom(128);*/
//assert(a - b == sosc::BigUInt("feff01"));
//auto d = sosc::BigUInt::DivideWithRemainder(a, b);
/*for(int i = a.ByteCount() * 8 - 1; i >= 0; --i) {
std::cout << a.GetBit(i);
b.SetBit(i, a.GetBit(i));
}*/
//std::cout << sosc::BigUInt::GenerateRandomPrime(64).ToString();
//std::cout << a.IsProbablePrime();
//for(int i = 0; i < 250; ++i)
time_t start = time(NULL);
/*auto d = sosc::BigUInt::DivideWithRemainder(a, b);
std::cout << d.result.ToString() << std::endl
<< d.remainder.ToString() << std::endl;*/
std::cout //<< a.ToString() << std::endl
//<< b.ToString() << std::endl
//<< (a * b).ToString() << std::endl;
//<< c.ToString() << std::endl << std::endl
//<< sosc::BigUInt::ModPow(a, b, c).ToString() << std::endl;
<< sosc::BigUInt::GenerateRandomPrime(16).ToString() << std::endl
<< sosc::BigUInt::GenerateRandomPrime(16).ToString() << std::endl
<< sosc::BigUInt::GenerateRandomPrime(16).ToString() << std::endl
<< sosc::BigUInt::GenerateRandomPrime(16).ToString() << std::endl;
std::cout << (time(NULL) - start) << std::endl;
//std::cout << a.ToString();
//std::cout << a.ToString();
/*std::cout << std::endl << std::endl
<< d.result.ToString()
<< std::endl
<< d.remainder.ToString();*/
return 0; return 0;
} }

View file

@ -1,2 +1,69 @@
#include "scapesock.hpp" #include "scapesock.hpp"
/**********************************/
/* BEGIN SCAPECONNECTION CODE */
/**********************************/
sosc::ScapeConnection::ScapeConnection() {
this->client_open = false;
this->handshaked = false;
}
void sosc::ScapeConnection::Open(TcpClient client) {
this->client = client;
this->client_open = true;
}
int sosc::ScapeConnection::Handshake() {
if(this->handshaked)
return SOSC_SHAKE_DONE;
if(!this->client_open)
return SOSC_SHAKE_ERR;
if(!this->client.IsDataReady())
return SOSC_SHAKE_CONT;
this->client.Receive(&this->buffer, SOSC_TCP_APPEND);
if(!str::contains(this->buffer, "\r\n\r\n"))
return SOSC_SHAKE_CONT;
if(!str::starts(this->buffer, "GET")) {
this->Close();
return SOSC_SHAKE_ERR;
}
auto lines = str::split(this->buffer, "\r\n");
this->handshaked = true;
return SOSC_SHAKE_DONE;
}
/******************************/
/* END SCAPECONNECTION CODE */
/******************************/
/* BEGIN SCAPESERVER CODE */
/******************************/
sosc::ScapeServer::ScapeServer() {
this->server_open = false;
}
bool sosc::ScapeServer::Listen(uint16_t port) {
if(this->server_open)
return false;
this->server = TcpServer();
this->server.Listen(port);
this->server_open = true;
return true;
}
int sosc::ScapeServer::Accept(ScapeConnection* client) {
TcpClient raw_client;
int status = this->server.Accept(&raw_client);
if(status != 0)
return status;
return 0;
}

View file

@ -4,11 +4,16 @@
#include "packet.hpp" #include "packet.hpp"
#include "tcpsock.hpp" #include "tcpsock.hpp"
#define SOSC_SHAKE_ERR -1
#define SOSC_SHAKE_CONT 0
#define SOSC_SHAKE_DONE 1
namespace sosc { namespace sosc {
class ScapeConnection { class ScapeConnection {
public: public:
ScapeConnection(); ScapeConnection();
int Handshake();
int Receive(Packet* packet, bool block = false); int Receive(Packet* packet, bool block = false);
bool Send(const Packet& packet); bool Send(const Packet& packet);
@ -16,6 +21,10 @@ public:
return this->client_open; return this->client_open;
} }
inline bool Handshaked() const {
return this->handshaked;
}
inline void Close() { inline void Close() {
this->client_open = false; this->client_open = false;
this->client.Close(); this->client.Close();
@ -26,6 +35,7 @@ private:
void Open(TcpClient client); void Open(TcpClient client);
bool client_open; bool client_open;
bool handshaked;
TcpClient client; TcpClient client;
std::string buffer; std::string buffer;

View file

@ -114,3 +114,9 @@ bool sosc::str::ends
end.begin(), end.end(), str.end() - end.length() end.begin(), end.end(), str.end() - end.length()
).first == end.end(); ).first == end.end();
} }
bool sosc::str::contains
(const std::string& haystack, const std::string& needle)
{
return haystack.find(needle) != std::string::npos;
}

View file

@ -33,6 +33,8 @@ std::string join(const std::vector<std::string>& parts,
bool starts(const std::string& str, const std::string& start); bool starts(const std::string& str, const std::string& start);
bool ends(const std::string& str, const std::string& end); bool ends(const std::string& str, const std::string& end);
bool contains(const std::string& haystack, const std::string& needle);
}} }}
#endif #endif