Project it

Having drawn a red teapot in 3D, I consider it my duty to briefly describe how it is done.

Modern OpenGL does not draw 3D, it only draws triangles, points, etc. in 2D screen coordinates.
To output anything with OpenGL, you need to provide a vertex buffer, write a vertex shader, add all the necessary matrices (projection, model, view) to the vertex shader, link all the input data to the shader, call the rendering method in OpenGL. Seems simple?


Ok, what is a vertex buffer? A list of coordinates to draw (x, y, z)
The vertex shader tells the GPU what coordinates to draw.
A pixel shader tells what to draw (color, texture, blending, etc.)
Matrices translate 3D coordinates into 2D coordinates OpenGL can render

In the following articles I will provide code examples and the result.

SDL2 – OpenGL ES

I love Panda3D game engine. But right now this engine is very hard to compile and debug on Microsoft Windows operation system. So as I said some time ago, I begin to develop my own graphics library. Right now it’s based on OpenGL ES and SDL2.
In this article I am going to tell how to initialize OpenGL ES context and how SDL2 helps in this task. We are going to show nothing.

King Nothing

First of all you need to install OpenGL ES3 – GLES 3 libraries. This operation is platform dependant, for Ubuntu Linux you can just type sudo apt-get install libgles2-mesa-dev. To work with OpenGL you need to initialize OpenGL context. There is many ways to do that, by using one of libraries – SDL2, GLFW, GLFM etc. Actually there is no one right way to initialize OpenGL context, but I chose SDL2 because it’s cross-platform solution, code will look same for Windows/*nix/HTML5/iOS/Android/etc.

To install sdl2 on Ubuntu use this command sudo apt-get install libsdl2-dev

So here is OpenGL context initialization code with SDL2:

    SDL_Window *window = SDL_CreateWindow(
            "SDL2 - OGLES",
            SDL_WINDOWPOS_UNDEFINED,
            SDL_WINDOWPOS_UNDEFINED,
            640,
            480,
            SDL_WINDOW_OPENGL
            );
	    

    SDL_GLContext glContext = SDL_GL_CreateContext(window);

After that, you can use any OpenGL calls in that context.

Here is example code for this article:
https://github.com/demensdeum/OpenGLES3-Experiments/tree/master/3sdl-gles
https://github.com/demensdeum/OpenGLES3-Experiments/blob/master/3sdl-gles/sdlgles.cpp

You can build and test it with command cmake . && make && ./SDLGles

Flame Steel Core

Screenshot from the latest version of Death Mask:

Looks like a million dollars huh?

< /blockquote>

Renaming, splitting

The Flame Steel Engine library has been renamed to Flame Steel Core, Game Toolkit has been split into SDL, Panda3D (Desktop) and Web (ThreeJS) libraries. If you have steel balls to build with Flame Steel libraries, you should first select and build the ones you need.

Github:

https://github.com/demensdeum/Death-Mask
https://github.com/demensdeum/FlameSteelCore
https://github.com/demensdeum/FlameSteelEngineGameToolkit
https://github.com/demensdeum/FlameSteelEngineGameToolkitDesktop

Deprecated:

https://github.com/demensdeum/FlameSteelEngineGameToolkitSDL
https://github.com/demensdeum/FlameSteelEngineGameToolkitWeb

Quantum hacking of RSA

The other day I wrote my implementation of the RSA public key encryption algorithm. I also did a simple hack of this algorithm, so I wanted to write a short note on this topic. RSA’s resistance to hacking is based on the factorization problem. Factorization… What a scary word.

It’s not all that bad

In fact, at the first stage of creating keys, we take two random numbers, but the numbers should only be divisible by themselves and one – prime numbers.
Let’s call them p and q. Next, we should get the number n = p *q. It will be used for further key generation, the keys in turn will be used for encryption, decryption of messages. In the final version of the private and public key, the number n will be transmitted unchanged.
Let’s say we have one of the RSA keys and an encrypted message. We extract the number n from the key and start hacking it.

Factorize n

Factorization – decomposition of a number into prime factors. First, we extract the number n from the key (on real keys, this can be done using openssl), let’s say n = 35. Then we decompose into prime factors n = 35 = 5 * 7, this is our p and q. Now we can regenerate keys using the obtained p, q, decrypt the message and encrypt, ensuring the visibility of the original author.

Qubits are not that simple

Is it really possible to break any RSA so easily? Actually, no, the numbers p, q are taken deliberately large so that the factorization task on classical computers would take a very long time (10 years to some degree)
However, using Shor’s quantum algorithm, it is possible to factor a number in a very short time. At the moment, articles on this topic state the time of multiplication of this number, i.e., practically instantly. For Shor’s algorithm to work, it is necessary to implement quantum computers with a large number of qubits. In 2001, IBM factored the number 15 into prime factors using 7 qubits. So we will have to wait a long time for this moment, by which time we will have switched to post-quantum encryption algorithms.

Touch Shor

Peter Shor talks about his factorization algorithm

To try out Shor’s algorithm on a quantum simulator, you can install ProjectQ, whose examples include an implementation of shor.py that allows you to factorize a number entered by the user. On the simulator, the execution time is depressing, but it seems to simulate the work of a quantum computer in a fun and playful way.

Articles:
http://www.pagedon.com/rsa-explained-simply/my_programming/
http://southernpacificreview.com/2014/01/06/rsa-key-generation-example/
https://0day.work/how-i-recovered-your-private-key-or-why-small-keys-are-bad/

RSA implementation in Python:
https://github.com/demensdeum/RSA-Python

Russian Quantum Hack and Number Generator

[Translation may be, some day]

Эта заметка увеличит длину вашего резюме на 5 см!

Без лишних слов о крутости квантовых компьютеров и всего такого, сегодня я покажу как сделать генератор чисел на реальном квантовом процессоре IBM.
Для этого мы будем использовать всего один кубит, фреймворк для разработки квантового ПО для python – ProjectQ, и 16 кубитовый процессор от IBM, онлайн доступ к которому открыт любому желающему по программе IBM Quantum Experience.

Установка ProjectQ

Для начала у вас должен быть Linux, Python и pip. Какие либо инструкции по установке этих базовых вещей приводить бесполезно, т.к. в любом случае инструкции устареют через неделю, поэтому просто найдите гайд по установке на официальном сайте. Далее устанавливаем ProjectQ, гайд по установке приведен в документации. На данный момент все свелось к установке пакета ProjectQ через pip, одной командой: python -m pip install –user projectq

Ставим кубит в суперпозицию

Создаем файл quantumNumberGenerator.py и берем пример генератора бинарного числа из документации ProjectQ, просто добавляем в него цикл на 32 шага, собираем бинарную строку и переводим в 32-битное число:

import projectq.setups.ibm
from projectq.ops import H, Measure
from projectq import MainEngine
from projectq.backends import IBMBackend

binaryString = ""

eng = MainEngine()

for i in range(1, 33):

 qubit = eng.allocate_qubit()

 H | qubit

 Measure | qubit

 eng.flush()

 binaryString = binaryString + str(int(qubit))

 print("Step " + str(i))

number = int(binaryString, 2)

print("\n--- Quantum 32-Bit Number Generator by demensdeum@gmail.com (2017) ---\n")
print("Binary: " + binaryString)
print("Number: " + str(number))
print("\n---")

Запускаем и получаем число из квантового симулятора с помощью команды python quantumNumberGenerator.py

Незнаю как вы, но я получил вывод и число 3974719468:

--- Quantum 32-Bit Number Generator by demensdeum@gmail.com (2017) ---

Binary: 11101100111010010110011111101100
Number: 3974719468

---

Хорошо, теперь мы запустим наш генератор на реальном квантовом процессоре IBM.

Хакаем IBM

Проходим регистрацию на сайте IBM Quantum Experience, подтверждаем email, в итоге должен остаться email и пароль для доступа.
Далее включаем айбиэмовский движок, меняем строку eng = MainEngine() -> eng = MainEngine(IBMBackend())
В теории после этого вы запускаете код снова и теперь он работает на реальном квантовом процессоре, используя один кубит. Однако после запуска вам придется 32 раза набрать свой email и пароль при каждой аллокации реального кубита. Обойти это можно прописав свой email и пароль прямо в библиотеки ProjectQ.

Заходим в папку где лежит фреймворк ProjectQ, ищем файл с помощью grep по строке IBM QE user (e-mail).
В итоге я исправил строки в файле projectq/backends/_ibm/_ibm_http_client.py:

email = input_fun('IBM QE user (e-mail) > ') -> email = "quantumPsycho@aport.ru"

password = getpass.getpass(prompt='IBM QE password > ') -> password = "ilovequbitsandicannotlie"

Напишите свой email и password со-но.

После этого IBM будет отправлять результаты работы с кубитом онлайн прямо в ваш скрипт, процесс генерации занимает около 20 секунд.

Возможно в дальнейшем я доберусь до работы квантового регистра, и возможно будет туториал, но это не обязательно.
Да прибудет с вами запутанность.

Статья на похожую тему:
Introducing the world’s first game for a quantum computer

Death Mask

From today I start developing a roguelike game in a cyberpunk setting – Death Mask.
In fact, this was supposed to be the first game on the new Flame Steel Engine toolchain, but the engine had to be improved before full 3D appeared.
The original title was “Flame Steel: Call Of The Death Mask”, then I decided to simplify the task and release only part of the game “Flame Steel: Zombie Night”
However, the idea of ​​creating a normal full-fledged project did not give me peace, and the name was also overloaded with the name of the Flame Steel universe.
For visual inspiration, I take the manga Biomega and Blame! as the Flame Steel universe itself is very similar to Shadowrun in space.
So don’t be surprised if in this game you meet an alien mage shooting a werewolf with magic bullets from a revolver, with precise aim from a cyber implant in his eye.

The game is being developed under an MIT open source license on GitHub, using the Flame Steel Engine toolchain and free frameworks.

GitHub:
https://github.com/demensdeum/Death-Mask