parent
1f5f756508
commit
d0457d9624
5 changed files with 96 additions and 104 deletions
After Width: | Height: | Size: 184 KiB |
@ -1,114 +1,101 @@ |
||||
#include <bakatools.h> |
||||
#include <math.h> |
||||
#include <stdlib.h> |
||||
#include "bakara/renderer/renderer.h" |
||||
#include "bakatools/logging/log.h" |
||||
#include "glm/ext/matrix_transform.hpp" |
||||
#include <bakara.h> |
||||
|
||||
long long int random(long long int max, long long int min = 0) |
||||
{ |
||||
long long int n = rand(); |
||||
while (n > max || n < min) n = rand(); |
||||
return n; |
||||
} |
||||
using namespace Bk; |
||||
|
||||
std::vector<long long int> prime_range(long long int max, long long int min = 2)
|
||||
class TestLayer : public Layer |
||||
{ |
||||
//Sieve of Eratosthenes algo from https://www.baeldung.com/cs/prime-number-algorithms
|
||||
std::vector<long long int> primes; |
||||
std::vector<bool> primes_check(max); |
||||
std::fill(primes_check.begin(), primes_check.end(), true); |
||||
|
||||
for (long long int i = 2; i < sqrt(max); i++) |
||||
if (primes_check[i]) |
||||
public: |
||||
TestLayer() : Layer("Test")
|
||||
{ |
||||
long long int j = i * i; |
||||
while (j <= max) |
||||
{ |
||||
primes_check[j] = false; |
||||
j += i; |
||||
} |
||||
} |
||||
blueShader = Ref<Shader>(Shader::Create(R"( |
||||
#version 420 core |
||||
layout (location = 0) in vec3 aPos; |
||||
|
||||
for (long long int i = min; i < primes_check.size(); i++)
|
||||
if (primes_check[i]) primes.push_back(i); |
||||
uniform mat4 viewProjection; |
||||
uniform mat4 transform; |
||||
|
||||
return primes; |
||||
} |
||||
void main() { |
||||
gl_Position = viewProjection * transform * vec4(aPos, 1.0); |
||||
} |
||||
)", R"( |
||||
#version 420 core |
||||
|
||||
long long int gcd(long long int a, long long int b)
|
||||
{ |
||||
long long int temp; |
||||
while (b != 0) |
||||
{ |
||||
temp = a % b; |
||||
a = b; |
||||
b = temp; |
||||
} |
||||
return a; |
||||
} |
||||
|
||||
long long int power(long long int val, long long int power) |
||||
{ |
||||
long long int res = val; |
||||
for(long long int i = 1; i < power; i++) res *= val; |
||||
return res; |
||||
} |
||||
|
||||
|
||||
void rsa()
|
||||
{
|
||||
auto primes = prime_range(100, 50); |
||||
//long long int p = primes[random(primes.size())];
|
||||
//long long int q = primes[random(primes.size())];
|
||||
long long int p = 13; |
||||
long long int q = 17; |
||||
long long int n = p * q; |
||||
long long int phi = (p - 1) * (q - 1); |
||||
|
||||
long long int e = 2; |
||||
long long int k = 0; |
||||
while(e < phi) |
||||
{ |
||||
if (gcd(e, phi) == 1) k += 1; |
||||
if (k >= 20) break; |
||||
e += 1; |
||||
} |
||||
|
||||
long long int d = 0; |
||||
long long int j = 0; |
||||
while (j < 2)
|
||||
{ |
||||
d += 1; |
||||
if (1 == (e * d) % phi)
|
||||
out vec4 FragColor; |
||||
|
||||
void main() { |
||||
FragColor = vec4(0.0, 0.0, 0.5, 1.0); |
||||
} |
||||
)")); |
||||
|
||||
float squareVertices[7 * 3] = { |
||||
-0.5f, -0.5f, 0.0f, |
||||
0.5f, -0.5f, 0.0f, |
||||
0.5f, 0.5f, 0.0f, |
||||
-0.5f, 0.5f, 0.0f,
|
||||
}; |
||||
|
||||
squareVA = Ref<VertexArray>(VertexArray::Create()); |
||||
|
||||
Ref<VertexBuffer> squareVB = Ref<VertexBuffer>(VertexBuffer::Create(squareVertices, sizeof(squareVertices))); |
||||
squareVB->SetLayout({ |
||||
{ ShaderType::Float3, "aPos" } |
||||
}); |
||||
squareVA->AddVertexBuffer(squareVB); |
||||
|
||||
u32 squareIndices[6] = { 0, 1, 2, 0, 2, 3 }; |
||||
squareVA->SetIndexbuffer(Ref<IndexBuffer>(IndexBuffer::Create(squareIndices, sizeof(squareIndices) / sizeof(u32)))); |
||||
} |
||||
|
||||
void OnUpdate(DeltaTime dt) override |
||||
{ |
||||
j += 1; |
||||
if(Keyboard::KeyDown(KeyCode::W)) |
||||
cameraPos.y += cameraSpeed * dt; |
||||
if(Keyboard::KeyDown(KeyCode::S)) |
||||
cameraPos.y -= cameraSpeed * dt; |
||||
if(Keyboard::KeyDown(KeyCode::D)) |
||||
cameraPos.x += cameraSpeed * dt; |
||||
if(Keyboard::KeyDown(KeyCode::A)) |
||||
cameraPos.x -= cameraSpeed * dt; |
||||
if(Keyboard::KeyDown(KeyCode::Q)) |
||||
rotation -= rotationSpeed * dt; |
||||
if(Keyboard::KeyDown(KeyCode::E)) |
||||
rotation += rotationSpeed * dt; |
||||
|
||||
camera.SetPosition(cameraPos); |
||||
camera.SetRotation(rotation); |
||||
|
||||
Renderer::BeginScene(camera); |
||||
RenderCommand::Clear(0.1, 0.1, 0.1, 1.0); |
||||
for(int x = 0; x < 20; x += 2) |
||||
for(int y = 0; y < 20; y += 2) |
||||
Renderer::Submit(squareVA, blueShader, Math::translate(Mat4(1.0f), Vec3(x, y, 0))); |
||||
} |
||||
} |
||||
BK_INFO("p:{4} q:{5} n:{0} phi:{1} e:{2} d:{3}", n, phi, e, d, p, q); |
||||
|
||||
long long int msg = 20; |
||||
long long int C = power(msg, e) % n; |
||||
BK_INFO("{0} {1}", C, power(msg, e)); |
||||
long long int M = C ^ d % n; |
||||
BK_INFO(M); |
||||
} |
||||
private: |
||||
OrthographicCamera camera = { -10.0f, 10.0f, -10.0f, 10.0f }; |
||||
Ref<Shader> blueShader; |
||||
Ref<VertexArray> squareVA; |
||||
Vec3 cameraPos = {0, 0, 0}; |
||||
float cameraSpeed = 5.0f; |
||||
float rotation = 0.0f; |
||||
float rotationSpeed = 30.0f; |
||||
}; |
||||
|
||||
void diffi() |
||||
{ |
||||
long long int a, b, g, p, ga, gb, gab, gba; |
||||
a = 10030; |
||||
b = 10294; |
||||
g = 10927; |
||||
p = prime_range(1000, 900)[3]; |
||||
ga = g^a % p; |
||||
gb = g^b % p; |
||||
gab = ga^b % p; |
||||
gba = gb^a % p; |
||||
BK_INFO("a{0} b{1} g{2} p{3} ga{4} gb{5} gab{6} gba{7}", a, b, g, p, ga, gb, gab, gba); |
||||
|
||||
} |
||||
|
||||
int main() |
||||
class Sandbox : public Application
|
||||
{ |
||||
Bk::Log::init("Bakacypher"); |
||||
diffi(); |
||||
return 0; |
||||
public: |
||||
Sandbox()
|
||||
{
|
||||
h_window->SetVsync(true); |
||||
PushLayer(new TestLayer()); |
||||
} |
||||
}; |
||||
|
||||
|
||||
|
||||
Application* Bk::CreateApp(int argc, char** argv) { |
||||
return new Sandbox(); |
||||
} |
@ -1,11 +1,11 @@ |
||||
{ |
||||
"name": "Bakacrypt", |
||||
"name": "graphics", |
||||
"author": "anulax1225", |
||||
"git": "", |
||||
"packages": [ |
||||
{ |
||||
"author": "anulax1225", |
||||
"name": "bakatools" |
||||
"name": "bakara" |
||||
} |
||||
] |
||||
} |
Loading…
Reference in New Issue